Use compare_exchange_strong mutex_lock on non-windows sytems

This commit is contained in:
gingerBill
2026-02-02 10:50:30 +00:00
parent 20a7a645c2
commit cb50725b86

View File

@@ -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;
}