| 2244 | } |
| 2245 | |
| 2246 | func (q *atomicSemaphore) release() { |
| 2247 | // N.B. the "<= 0" check below should allow for this to work with multiple |
| 2248 | // concurrent calls to acquire, but also note that with synchronous calls to |
| 2249 | // acquire, as our system does, n will never be less than -1. There are |
| 2250 | // fairness issues (queuing) to consider if this was to be generalized. |
| 2251 | if q.n.Add(1) <= 0 { |
| 2252 | // An acquire was waiting on us. Unblock it. |
| 2253 | q.wait <- struct{}{} |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | func newHandlerQuota(n uint32) *atomicSemaphore { |
| 2258 | a := &atomicSemaphore{wait: make(chan struct{}, 1)} |