From b63ea3bad163e6a930c1e4ac7ede3ec18da46aaf Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 28 Sep 2021 12:32:46 +0330 Subject: [PATCH] LibPthread: Calculate the correct lock value in RWLock {rd,un}lock The previous version was putting the old count in the control bits, which is all kinds of wrong. --- Userland/Libraries/LibPthread/pthread.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibPthread/pthread.cpp b/Userland/Libraries/LibPthread/pthread.cpp index 8037f2fac8..86f9703f34 100644 --- a/Userland/Libraries/LibPthread/pthread.cpp +++ b/Userland/Libraries/LibPthread/pthread.cpp @@ -618,7 +618,7 @@ static int rwlock_rdlock_maybe_timed(u32* lockp, const struct timespec* timeout auto count = (u16)current; if (!(current & writer_intent_mask) || count > 1) { ++count; - auto desired = (current << 16) | count; + auto desired = (current & 0xffff0000u) | count; auto did_exchange = AK::atomic_compare_exchange_strong(lockp, current, desired, AK::MemoryOrder::memory_order_acquire); if (!did_exchange) continue; // tough luck, try again. @@ -779,7 +779,7 @@ int pthread_rwlock_unlock(pthread_rwlock_t* lockval_p) return EINVAL; } --count; - auto desired = (current << 16) | count; + auto desired = (current & 0xffff0000u) | count; auto did_exchange = AK::atomic_compare_exchange_strong(lockp, current, desired, AK::MemoryOrder::memory_order_release); if (!did_exchange) continue; // tough luck, try again.