Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated compare_and_swap with compare_exchange #18

Merged
merged 1 commit into from
Dec 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down