Skip to content

Commit

Permalink
feat: allow reusing CondVar object during CondVar::notify_all()
Browse files Browse the repository at this point in the history
  • Loading branch information
BorysTheDev committed Oct 19, 2024
1 parent 5719e24 commit e590cc7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions util/fibers/synchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,14 @@ class CondVarAny {
}

void notify_all() noexcept {
if (!wait_queue_.empty())
wait_queue_.NotifyAll(detail::FiberActive());
if (!wait_queue_.empty()) {
detail::WaitQueue tmp_queue;
// this allows reusing CondVarAny object during WaitQueue::NotifyAll() execution
// if another thread decided to wait again on this object
std::swap(tmp_queue, wait_queue_);
tmp_queue.NotifyAll(detail::FiberActive());
}

}

template <typename LockType> void wait(LockType& lt);
Expand Down

0 comments on commit e590cc7

Please sign in to comment.