From 6d0a175e06141d83b75a47215c5a90d9308d7afa Mon Sep 17 00:00:00 2001 From: KRM7 <70973547+KRM7@users.noreply.github.com> Date: Thu, 28 Mar 2024 23:09:54 +0100 Subject: [PATCH] Update spinlock.hpp --- src/utility/spinlock.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utility/spinlock.hpp b/src/utility/spinlock.hpp index 3a6efdcc..855e9c2e 100644 --- a/src/utility/spinlock.hpp +++ b/src/utility/spinlock.hpp @@ -5,7 +5,7 @@ #include "utility.hpp" #include -#include +#include namespace gapp::detail { @@ -16,9 +16,12 @@ namespace gapp::detail { while (true) { + if (!locked_.test_and_set(std::memory_order_relaxed)) + { + std::ignore = locked_.test(std::memory_order_acquire); + break; + } while (locked_.test(std::memory_order_relaxed)) GAPP_PAUSE(); - if (!locked_.test_and_set(std::memory_order_acquire)) break; - std::this_thread::yield(); } }