| 99 | explicit ThreadBarrier(size_t count) : threshold(count), count(count), generation(0) {} |
| 100 | |
| 101 | void wait() { |
| 102 | std::unique_lock<std::mutex> lock(mutex); |
| 103 | auto gen = generation; |
| 104 | |
| 105 | if (--count == 0) { |
| 106 | generation++; |
| 107 | count = threshold; |
| 108 | cond.notify_all(); |
| 109 | } else { |
| 110 | cond.wait(lock, [this, gen] { return gen != generation; }); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | private: |
| 115 | std::mutex mutex; |
no outgoing calls
no test coverage detected