diff --git a/src/lib.rs b/src/lib.rs index 7feff36..c4e5abd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -451,7 +451,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. @@ -460,7 +460,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); } diff --git a/src/single.rs b/src/single.rs index c6c007d..022c7e4 100644 --- a/src/single.rs +++ b/src/single.rs @@ -29,7 +29,8 @@ impl Single { // Lock and fill the slot. let state = self .state - .compare_and_swap(0, LOCKED | PUSHED, Ordering::SeqCst); + .compare_exchange(0, LOCKED | PUSHED, Ordering::SeqCst, Ordering::SeqCst) + .unwrap_or_else(|x| x); if state == 0 { // Write the value and unlock. @@ -48,9 +49,15 @@ impl Single { let mut state = PUSHED; loop { // Lock and empty the slot. - let prev = - self.state - .compare_and_swap(state, (state | LOCKED) & !PUSHED, Ordering::SeqCst); + let prev = self + .state + .compare_exchange( + state, + (state | LOCKED) & !PUSHED, + Ordering::SeqCst, + Ordering::SeqCst, + ) + .unwrap_or_else(|x| x); if prev == state { // Read the value and unlock. diff --git a/src/unbounded.rs b/src/unbounded.rs index 63270a1..c7cba68 100644 --- a/src/unbounded.rs +++ b/src/unbounded.rs @@ -172,8 +172,8 @@ impl Unbounded { if self .tail .block - .compare_and_swap(block, new, Ordering::Release) - == block + .compare_exchange(block, new, Ordering::Release, Ordering::Relaxed) + .is_ok() { self.head.block.store(new, Ordering::Release); block = new;