| 37 | } |
| 38 | |
| 39 | __forceinline void wait() |
| 40 | { |
| 41 | /* every thread entering the barrier decrements this count */ |
| 42 | size_t i0 = i; |
| 43 | size_t cnt0 = enterCount--; |
| 44 | |
| 45 | /* all threads except the last one are wait in the barrier */ |
| 46 | if (cnt0 > 1) |
| 47 | { |
| 48 | if (WaitForSingleObject(events[i0], INFINITE) != WAIT_OBJECT_0) |
| 49 | THROW_RUNTIME_ERROR("WaitForSingleObjects failed"); |
| 50 | } |
| 51 | |
| 52 | /* the last thread starts all threads waiting at the barrier */ |
| 53 | else |
| 54 | { |
| 55 | i = 1-i; |
| 56 | enterCount.store(barrierSize); |
| 57 | if (SetEvent(events[i0]) == 0) |
| 58 | THROW_RUNTIME_ERROR("SetEvent failed"); |
| 59 | } |
| 60 | |
| 61 | /* every thread leaving the barrier decrements this count */ |
| 62 | size_t cnt1 = exitCount--; |
| 63 | |
| 64 | /* the last thread that left the barrier resets the event again */ |
| 65 | if (cnt1 == 1) |
| 66 | { |
| 67 | exitCount.store(barrierSize); |
| 68 | if (ResetEvent(events[i0]) == 0) |
| 69 | THROW_RUNTIME_ERROR("ResetEvent failed"); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | public: |
| 74 | HANDLE events[2]; |
nothing calls this directly
no test coverage detected