Commit 9028b812 by AtariDreams Committed by Copybara-Service

PR #1589: Use compare_exchange_weak in the loop in Mutex::ReaderLock

Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1589

It makes sense because even if it fails spuriously, we can just try again since we have to check for other readers anyway.
Merge 0b1780299b9e43205202d6b25f6e57759722d063 into 6a19ff47

Merging this change closes #1589

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1589 from AtariDreams:atomics 0b1780299b9e43205202d6b25f6e57759722d063
PiperOrigin-RevId: 595149382
Change-Id: I24f678f6bf95c6a37b2ed541a2b6668a58a67702
parent 925a5e68
...@@ -1551,7 +1551,7 @@ void Mutex::ReaderLock() { ...@@ -1551,7 +1551,7 @@ void Mutex::ReaderLock() {
} }
// We can avoid the loop and only use the CAS when the lock is free or // We can avoid the loop and only use the CAS when the lock is free or
// only held by readers. // only held by readers.
if (ABSL_PREDICT_TRUE(mu_.compare_exchange_strong( if (ABSL_PREDICT_TRUE(mu_.compare_exchange_weak(
v, (kMuReader | v) + kMuOne, std::memory_order_acquire, v, (kMuReader | v) + kMuOne, std::memory_order_acquire,
std::memory_order_relaxed))) { std::memory_order_relaxed))) {
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment