Skip to content

Commit 194cf15

Browse files
committed
Revert "Fix fence on non-x86 arch and miri (#16)"
This reverts commit 54df36a.
1 parent b8363ba commit 194cf15

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

src/bounded.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ impl<T> Bounded<T> {
129129
}
130130
}
131131
} else if stamp.wrapping_add(self.one_lap) == tail + 1 {
132-
let head = crate::full_fence_for_load(|| self.head.load(Ordering::Relaxed));
132+
crate::full_fence();
133+
let head = self.head.load(Ordering::Relaxed);
133134

134135
// If the head lags one lap behind the tail as well...
135136
if head.wrapping_add(self.one_lap) == tail {
@@ -190,7 +191,8 @@ impl<T> Bounded<T> {
190191
}
191192
}
192193
} else if stamp == head {
193-
let tail = crate::full_fence_for_load(|| self.tail.load(Ordering::Relaxed));
194+
crate::full_fence();
195+
let tail = self.tail.load(Ordering::Relaxed);
194196

195197
// If the tail equals the head, that means the queue is empty.
196198
if (tail & !self.mark_bit) == head {

src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,8 @@ impl<T> fmt::Display for PushError<T> {
445445

446446
/// Equivalent to `atomic::fence(Ordering::SeqCst)`, but in some cases faster.
447447
#[inline]
448-
fn full_fence_for_load<T>(load_op: impl FnOnce() -> T) -> T {
449-
if cfg!(all(
450-
any(target_arch = "x86", target_arch = "x86_64"),
451-
not(miri)
452-
)) {
448+
fn full_fence() {
449+
if cfg!(any(target_arch = "x86", target_arch = "x86_64")) {
453450
// HACK(stjepang): On x86 architectures there are two different ways of executing
454451
// a `SeqCst` fence.
455452
//
@@ -464,11 +461,7 @@ fn full_fence_for_load<T>(load_op: impl FnOnce() -> T) -> T {
464461
// x86 platforms is going to optimize this away.
465462
let a = AtomicUsize::new(0);
466463
let _ = a.compare_exchange(0, 1, Ordering::SeqCst, Ordering::SeqCst);
467-
// On x86, `lock cmpxchg; mov` is fine. See also https://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html.
468-
load_op()
469464
} else {
470-
let res = load_op();
471465
atomic::fence(Ordering::SeqCst);
472-
res
473466
}
474467
}

src/unbounded.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ impl<T> Unbounded<T> {
237237
let mut new_head = head + (1 << SHIFT);
238238

239239
if new_head & MARK_BIT == 0 {
240-
let tail = crate::full_fence_for_load(|| self.tail.index.load(Ordering::Relaxed));
240+
crate::full_fence();
241+
let tail = self.tail.index.load(Ordering::Relaxed);
241242

242243
// If the tail equals the head, that means the queue is empty.
243244
if head >> SHIFT == tail >> SHIFT {

0 commit comments

Comments
 (0)