From 843770442c343b76ad5145c132e19ad6b7574d2d Mon Sep 17 00:00:00 2001 From: mutouyun Date: Fri, 17 Sep 2021 22:25:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8Dwait=5Fif=E7=9A=84counter?= =?UTF-8?q?=E5=9B=A0=E4=B8=BAABA=E9=97=AE=E9=A2=98=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E8=AE=A1=E6=95=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libipc/waiter_helper.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libipc/waiter_helper.h b/src/libipc/waiter_helper.h index a84f59c..a366461 100644 --- a/src/libipc/waiter_helper.h +++ b/src/libipc/waiter_helper.h @@ -33,9 +33,10 @@ struct waiter_helper { auto & counter = ctrl.counter(); counter.waiting_.fetch_add(1, std::memory_order_release); flags.is_waiting_.store(true, std::memory_order_relaxed); - auto finally = ipc::guard([&counter, &flags] { - for (auto curr_wait = counter.waiting_.load(std::memory_order_acquire); curr_wait > 0;) { - if (counter.waiting_.compare_exchange_weak(curr_wait, curr_wait - 1, std::memory_order_release)) { + auto finally = ipc::guard([&ctrl, &counter, &flags] { + ctrl.get_lock(); // barrier + for (auto curr_wait = counter.waiting_.load(std::memory_order_relaxed); curr_wait > 0;) { + if (counter.waiting_.compare_exchange_weak(curr_wait, curr_wait - 1, std::memory_order_acq_rel)) { break; } }