From f79c7ae83e03f172650d15411b63045b2e9f750f Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 12 Jun 2023 23:53:39 -0400 Subject: [PATCH] pthread_cond: Use test_and_set in cond_wait. This is necessary in the case where only one thread is being woken up at a time. --- src/system/libroot/posix/pthread/pthread_cond.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/libroot/posix/pthread/pthread_cond.cpp b/src/system/libroot/posix/pthread/pthread_cond.cpp index dc6d9d1e5f..eca5f03c96 100644 --- a/src/system/libroot/posix/pthread/pthread_cond.cpp +++ b/src/system/libroot/posix/pthread/pthread_cond.cpp @@ -74,7 +74,7 @@ cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex, uint32 flags, cond->waiter_count++; // make sure the user mutex we use for blocking is locked - atomic_or((int32*)&cond->lock, B_USER_MUTEX_LOCKED); + atomic_test_and_set((int32*)&cond->lock, B_USER_MUTEX_LOCKED, 0); // atomically unlock the mutex and start waiting on the user mutex mutex->owner = -1;