| 43 | #endif |
| 44 | |
| 45 | void Barrier::wait() |
| 46 | { |
| 47 | unique_lock<mutex> lock(m_barrierMutex); |
| 48 | // Decrement number of threads awaited at the barrier |
| 49 | m_waiting--; |
| 50 | if (m_waiting == 0) { |
| 51 | // Called by the last expected thread - notify all waiting threads and exit |
| 52 | m_cVar.notify_all(); |
| 53 | // Store the time when barrier was released |
| 54 | if (m_releasedAt.tv_sec == 0 && m_releasedAt.tv_nsec == 0) { |
| 55 | clock_gettime(CLOCK_MONOTONIC, &m_releasedAt); |
| 56 | } |
| 57 | return; |
| 58 | } |
| 59 | // Wait unitl the last expected thread calls wait() on Barrier instance, or timeout occurs |
| 60 | m_cVar.wait_until(lock, ch::system_clock::now() + ch::seconds(10), []() { |
| 61 | return GetInstance().m_waiting == 0; |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | // Worker class |
| 66 | Worker::Worker( |
no outgoing calls
no test coverage detected