| 63 | } |
| 64 | |
| 65 | void wait_group::wait() |
| 66 | { |
| 67 | for(;;) { |
| 68 | long long state = state_; |
| 69 | int c = (int) (state >> 32); |
| 70 | |
| 71 | // Return if no tasks. |
| 72 | if (c == 0) { |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | // Increase the number of waiters, or get state again if failed. |
| 77 | if (state_.cas(state, state + 1) == state) { |
| 78 | bool found; |
| 79 | #ifdef _DEBUG |
| 80 | unsigned long* tid = box_->pop(-1, &found); |
| 81 | assert(found); |
| 82 | delete tid; |
| 83 | #else |
| 84 | (void) box_->pop(-1, &found); |
| 85 | assert(found); |
| 86 | #endif |
| 87 | if(state_ == 0) { |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | logger_fatal("Reused before previous wait has returned"); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | } // namespace acl |