| 82 | } |
| 83 | |
| 84 | bool AsyncGroup::blockingWaitWithTimeout(const std::chrono::steady_clock::duration& maxTime) { |
| 85 | std::unique_lock<Mutex> guard(_mutex); |
| 86 | if (_enterCount == 0) { |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | auto cond = makeShared<ConditionVariable>(); |
| 91 | |
| 92 | while (_enterCount != 0) { |
| 93 | auto functionId = lockFreeEnqueueFunction([cond]() { cond->notifyAll(); }); |
| 94 | |
| 95 | auto status = cond->waitFor(guard, maxTime); |
| 96 | |
| 97 | lockFreeRemoveFunction(functionId); |
| 98 | |
| 99 | if (status == std::cv_status::timeout) { |
| 100 | return false; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | int AsyncGroup::lockFreeEnqueueFunction(DispatchFunction function) { |
| 108 | auto id = ++_callbackSequence; |