newSemaphore creates a semaphore with the desired initial capacity.
(maxCapacity, initialCapacity int)
| 180 | |
| 181 | // newSemaphore creates a semaphore with the desired initial capacity. |
| 182 | func newSemaphore(maxCapacity, initialCapacity int) *semaphore { |
| 183 | queue := make(chan struct{}, maxCapacity) |
| 184 | sem := &semaphore{queue: queue} |
| 185 | sem.updateCapacity(initialCapacity) |
| 186 | return sem |
| 187 | } |
| 188 | |
| 189 | // semaphore is an implementation of a semaphore based on packed integers and a channel. |
| 190 | // state is an uint64 that has two uint32s packed into it: capacity and inFlight. The |