From 1ce02e82ff2818df129c0d1d27ce5c3db962e8f2 Mon Sep 17 00:00:00 2001 From: Tapish Date: Mon, 29 Jul 2024 13:14:29 +0200 Subject: [PATCH] Improve cv --- redGrapes/sync/cv.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/redGrapes/sync/cv.hpp b/redGrapes/sync/cv.hpp index 7fb443a1..2c08422a 100644 --- a/redGrapes/sync/cv.hpp +++ b/redGrapes/sync/cv.hpp @@ -63,22 +63,22 @@ namespace redGrapes } } - should_wait.store(true); + should_wait.store(true, std::memory_order_release); } bool notify() { - bool w = true; - should_wait.compare_exchange_strong(w, false, std::memory_order_release); - - // TODO: check this optimization - // if( ! busy.test_and_set(std::memory_order_acquire) ) + bool expected = true; + if(should_wait + .compare_exchange_strong(expected, false, std::memory_order_release, std::memory_order_relaxed)) { - std::unique_lock l(m); + // TODO: check this optimization + // if( ! busy.test_and_set(std::memory_order_acquire) ) + std::unique_lock l(m); cv.notify_all(); + return true; } - - return w; + return false; } };