From d4aa0302dc10c500386f7c48e1dad6d9d6c59576 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 24 Dec 2020 21:19:23 +0900 Subject: [PATCH] Replace deprecated compare_and_swap with compare_exchange --- src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8a5c4e0..9b7a504 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -392,7 +392,10 @@ impl Event { let new = Arc::into_raw(new) as *mut Inner; // Attempt to replace the null-pointer with the new state pointer. - inner = self.inner.compare_and_swap(inner, new, Ordering::AcqRel); + inner = self + .inner + .compare_exchange(inner, new, Ordering::AcqRel, Ordering::Acquire) + .unwrap_or_else(|x| x); // Check if the old pointer value was indeed null. if inner.is_null() { @@ -970,7 +973,7 @@ fn full_fence() { // a `SeqCst` fence. // // 1. `atomic::fence(SeqCst)`, which compiles into a `mfence` instruction. - // 2. `_.compare_and_swap(_, _, SeqCst)`, which compiles into a `lock cmpxchg` instruction. + // 2. `_.compare_exchange(_, _, SeqCst, SeqCst)`, which compiles into a `lock cmpxchg` instruction. // // Both instructions have the effect of a full barrier, but empirical benchmarks have shown // that the second one is sometimes a bit faster. @@ -979,7 +982,7 @@ fn full_fence() { // temporary atomic variable and compare-and-exchanging its value. No sane compiler to // x86 platforms is going to optimize this away. let a = AtomicUsize::new(0); - a.compare_and_swap(0, 1, Ordering::SeqCst); + let _ = a.compare_exchange(0, 1, Ordering::SeqCst, Ordering::SeqCst); } else { atomic::fence(Ordering::SeqCst); }