| 45 | } |
| 46 | |
| 47 | void wait() { |
| 48 | std::unique_lock<std::mutex> lock(mutex); |
| 49 | size_t currentPhase = phase; |
| 50 | |
| 51 | // Check if we're the last thread. |
| 52 | if (++count >= threads) { |
| 53 | // Advance phase and reset count |
| 54 | count = 0; |
| 55 | phase++; |
| 56 | // Notify all other threads |
| 57 | cv.notify_all(); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | // Unlock and wait on phase to change |
| 62 | cv.wait(lock, [&] { |
| 63 | return phase != currentPhase; |
| 64 | }); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 |
no outgoing calls
no test coverage detected