From e590cc7150186235af929df23680097f77af2ca2 Mon Sep 17 00:00:00 2001 From: Borys Date: Sat, 19 Oct 2024 22:48:10 +0300 Subject: [PATCH] feat: allow reusing CondVar object during CondVar::notify_all() --- util/fibers/synchronization.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/util/fibers/synchronization.h b/util/fibers/synchronization.h index e5c05f5a..6affd0a7 100644 --- a/util/fibers/synchronization.h +++ b/util/fibers/synchronization.h @@ -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 void wait(LockType& lt);