浏览代码

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.
Ali Mohammad Pur 3 年之前
父节点
当前提交
72a45a472a
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      Userland/Libraries/LibPthread/pthread.cpp

+ 3 - 2
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!