Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down
15 changes: 11 additions & 4 deletions src/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ impl<T> Single<T> {
// 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.
Expand All @@ -48,9 +49,15 @@ impl<T> Single<T> {
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.
Expand Down
4 changes: 2 additions & 2 deletions src/unbounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ impl<T> Unbounded<T> {
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;
Expand Down