From ca458a2b55da6bfae12346076c9ec67c5244bcf7 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 12 Jun 2023 23:27:45 -0400 Subject: [PATCH] user_mutex: Adjust semantics of B_USER_MUTEX_UNBLOCK_ALL. No longer is it required that the mutex be unlocked. This was the case before the recent refactor, though it wasn't noted anywhere. Now it is the case once more. Should fix #18445. --- src/system/kernel/locks/user_mutex.cpp | 11 ++++++++--- src/system/libroot/posix/pthread/pthread_barrier.cpp | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/system/kernel/locks/user_mutex.cpp b/src/system/kernel/locks/user_mutex.cpp index d6fb65b8e7..dad7328d43 100644 --- a/src/system/kernel/locks/user_mutex.cpp +++ b/src/system/kernel/locks/user_mutex.cpp @@ -222,9 +222,14 @@ user_mutex_unblock_locked(int32* mutex, phys_addr_t physicalAddress, uint32 flag } // Someone is waiting: try to hand off the lock to them, if possible. - int32 oldValue = user_atomic_or(mutex, B_USER_MUTEX_LOCKED); - if ((oldValue & B_USER_MUTEX_LOCKED) != 0) - return; + int32 oldValue = 0; + if ((flags & B_USER_MUTEX_UNBLOCK_ALL) == 0) { + oldValue = user_atomic_or(mutex, B_USER_MUTEX_LOCKED); + if ((oldValue & B_USER_MUTEX_LOCKED) != 0) + return; + } else { + oldValue = user_atomic_get(mutex); + } // unblock the first thread entry->locked = true; diff --git a/src/system/libroot/posix/pthread/pthread_barrier.cpp b/src/system/libroot/posix/pthread/pthread_barrier.cpp index 470fa1e6aa..c484165f72 100644 --- a/src/system/libroot/posix/pthread/pthread_barrier.cpp +++ b/src/system/libroot/posix/pthread/pthread_barrier.cpp @@ -97,7 +97,6 @@ pthread_barrier_wait(pthread_barrier_t* barrier) // Wake everyone else up. barrier->waiter_count = (-barrier->waiter_max) + 1; - atomic_and((int32*)&barrier->lock, ~(int32)B_USER_MUTEX_LOCKED); _kern_mutex_unblock((int32*)&barrier->lock, B_USER_MUTEX_UNBLOCK_ALL); // Return with the barrier mutex still locked, as waiter_count < 0.