updateCapacity updates the capacity of the semaphore to the desired size.
(size int)
| 271 | |
| 272 | // updateCapacity updates the capacity of the semaphore to the desired size. |
| 273 | func (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. |
| 300 | func (s *semaphore) Capacity() int { |