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

Method tryAcquirePending

pkg/proxy/breaker.go:83–107  ·  view source on GitHub ↗

tryAcquirePending tries to acquire a slot on the pending "queue".

()

Source from the content-addressed store, hash-verified

81
82// tryAcquirePending tries to acquire a slot on the pending "queue".
83func (b *Breaker) tryAcquirePending() bool {
84 // This is an atomic version of:
85 //
86 // if inFlight == totalSlots {
87 // return false
88 // } else {
89 // inFlight++
90 // return true
91 // }
92 //
93 // We can't just use an atomic increment as we need to check if we're
94 // "allowed" to increment first. Since a Load and a CompareAndSwap are
95 // not done atomically, we need to retry until the CompareAndSwap succeeds
96 // (it fails if we're raced to it) or if we don't fulfill the condition
97 // anymore.
98 for {
99 cur := b.inFlight.Load()
100 if cur == b.totalSlots {
101 return false
102 }
103 if b.inFlight.CAS(cur, cur+1) {
104 return true
105 }
106 }
107}
108
109// releasePending releases a slot on the pending "queue".
110func (b *Breaker) releasePending() {

Callers 2

ReserveMethod · 0.95
MaybeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected