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

Method release

pkg/proxy/breaker.go:245–270  ·  view source on GitHub ↗

release releases capacity in the semaphore. If the semaphore capacity was reduced in between and as a result inFlight is greater than capacity, we don't wake up goroutines as they'd not get any capacity anyway.

()

Source from the content-addressed store, hash-verified

243// If the semaphore capacity was reduced in between and as a result inFlight is greater
244// than capacity, we don't wake up goroutines as they'd not get any capacity anyway.
245func (s *semaphore) release() {
246 for {
247 old := s.state.Load()
248 capacity, in := unpack(old)
249
250 if in == 0 {
251 panic("release and acquire are not paired")
252 }
253
254 in--
255 if s.state.CAS(old, pack(capacity, in)) {
256 if in < capacity {
257 select {
258 case s.queue <- struct{}{}:
259 default:
260 // We generate more wakeups than we might need as we don't know
261 // how many goroutines are waiting here. It is therefore okay
262 // to drop the poke on the floor here as this case would mean we
263 // have enough wakeups to wake up as many goroutines as this semaphore
264 // can take, which is guaranteed to be enough.
265 }
266 }
267 return
268 }
269 }
270}
271
272// updateCapacity updates the capacity of the semaphore to the desired size.
273func (s *semaphore) updateCapacity(size int) {

Callers 3

TestSemaphoreReleaseFunction · 0.80
NewBreakerFunction · 0.80
MaybeMethod · 0.80

Calls 2

unpackFunction · 0.85
packFunction · 0.85

Tested by 1

TestSemaphoreReleaseFunction · 0.64