MCPcopy
hub / github.com/cortexlabs/cortex / updateCapacity

Method updateCapacity

pkg/proxy/breaker.go:273–297  ·  view source on GitHub ↗

updateCapacity updates the capacity of the semaphore to the desired size.

(size int)

Source from the content-addressed store, hash-verified

271
272// updateCapacity updates the capacity of the semaphore to the desired size.
273func (s *semaphore) updateCapacity(size int) {
274 s64 := uint64(size)
275 for {
276 old := s.state.Load()
277 capacity, in := unpack(old)
278
279 if capacity == s64 {
280 // Nothing to do, exit early.
281 return
282 }
283
284 if s.state.CAS(old, pack(s64, in)) {
285 if s64 > capacity {
286 for i := uint64(0); i < s64-capacity; i++ {
287 select {
288 case s.queue <- struct{}{}:
289 default:
290 // See comment in `release` for explanation of this case.
291 }
292 }
293 }
294 return
295 }
296 }
297}
298
299// Capacity is the capacity of the semaphore.
300func (s *semaphore) Capacity() int {

Callers 4

newSemaphoreFunction · 0.95
UpdateConcurrencyMethod · 0.80

Calls 2

unpackFunction · 0.85
packFunction · 0.85

Tested by 2