diff options
author | AtariDreams <83477269+AtariDreams@users.noreply.github.com> | 2024-01-02 10:18:46 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-01-02 10:19:37 -0800 |
commit | 9028b8126dde250ddc193a7088ceebbbb20bac92 (patch) | |
tree | 05b7c058ff6bb57a7831f1142036ca449dc0ae02 /absl/synchronization | |
parent | 925a5e681ea1958171ba580c4402e5ce76473cb5 (diff) | |
download | abseil-9028b8126dde250ddc193a7088ceebbbb20bac92.tar.gz abseil-9028b8126dde250ddc193a7088ceebbbb20bac92.tar.bz2 abseil-9028b8126dde250ddc193a7088ceebbbb20bac92.zip |
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 6a19ff47352a2112e953f4ab813d820e0ecfe1e3
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
Diffstat (limited to 'absl/synchronization')
-rw-r--r-- | absl/synchronization/mutex.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc index 98574c0b..cb3c7e74 100644 --- a/absl/synchronization/mutex.cc +++ b/absl/synchronization/mutex.cc @@ -1551,7 +1551,7 @@ void Mutex::ReaderLock() { } // We can avoid the loop and only use the CAS when the lock is free or // 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, std::memory_order_relaxed))) { break; |