diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-09-28 12:34:51 +0330 |
---|---|---|
committer | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-09-28 12:34:51 +0330 |
commit | 72a45a472aa3ce4dfc97c68beeebe95b3df34e23 (patch) | |
tree | ae62d7f68ffb932328e9c789b8c7edf889f1d750 | |
parent | b63ea3bad163e6a930c1e4ac7ede3ec18da46aaf (diff) | |
download | serenity-72a45a472aa3ce4dfc97c68beeebe95b3df34e23.zip |
LibPthread: Correct nonsensical loop exit condition in RWLock unlock
The loop should terminate after the exchange happens, we shouldn't
repeat the operation until the count hits zero.
Fixes #10241.
-rw-r--r-- | Userland/Libraries/LibPthread/pthread.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Userland/Libraries/LibPthread/pthread.cpp b/Userland/Libraries/LibPthread/pthread.cpp index 86f9703f34..dc1088c72b 100644 --- a/Userland/Libraries/LibPthread/pthread.cpp +++ b/Userland/Libraries/LibPthread/pthread.cpp @@ -781,8 +781,9 @@ int pthread_rwlock_unlock(pthread_rwlock_t* lockval_p) --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. + if (did_exchange) + break; + // tough luck, try again. } // Finally, unlocked at last! |