From cb50725b866ef7020f9bd82a1c39d4d8f7158e97 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 2 Feb 2026 10:50:30 +0000 Subject: Use `compare_exchange_strong` `mutex_lock` on non-windows sytems --- src/threading.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/threading.cpp b/src/threading.cpp index 02e6de14b..3b2f304e1 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -367,16 +367,16 @@ gb_internal void semaphore_wait(Semaphore *s) { gb_internal void mutex_lock(BlockingMutex *m) { ANNOTATE_LOCK_PRE(m, 0); - i32 v = m->state().exchange(Internal_Mutex_State_Locked, std::memory_order_acquire); - if (v != Internal_Mutex_State_Unlocked) { + i32 expected = Internal_Mutex_State_Unlocked; + if (m->state().compare_exchange_strong(expected, Internal_Mutex_State_Locked, std::memory_order_acquire)) { mutex_lock_slow(m, v); } ANNOTATE_LOCK_POST(m); } gb_internal bool mutex_try_lock(BlockingMutex *m) { ANNOTATE_LOCK_PRE(m, 1); - i32 v = m->state().exchange(Internal_Mutex_State_Locked, std::memory_order_acquire); - if (v == Internal_Mutex_State_Unlocked) { + i32 expected = Internal_Mutex_State_Unlocked; + if (m->state().compare_exchange_strong(expected, Internal_Mutex_State_Locked, std::memory_order_acquire)) { ANNOTATE_LOCK_POST(m); return true; } -- cgit v1.2.3