diff --git a/tokio-sync/src/loom.rs b/tokio-sync/src/loom.rs index 92a21e5ba..39755c016 100644 --- a/tokio-sync/src/loom.rs +++ b/tokio-sync/src/loom.rs @@ -31,6 +31,8 @@ pub(crate) mod sync { } } -pub(crate) fn yield_now() { - ::std::sync::atomic::spin_loop_hint(); +pub(crate) mod thread { + pub(crate) fn yield_now() { + ::std::sync::atomic::spin_loop_hint(); + } } diff --git a/tokio-sync/src/mpsc/block.rs b/tokio-sync/src/mpsc/block.rs index bf1c7b153..f1d84c695 100644 --- a/tokio-sync/src/mpsc/block.rs +++ b/tokio-sync/src/mpsc/block.rs @@ -1,7 +1,7 @@ use crate::loom::{ - self, sync::atomic::{AtomicPtr, AtomicUsize}, sync::CausalCell, + thread, }; use std::mem::{self, ManuallyDrop}; use std::ops; @@ -344,7 +344,7 @@ impl Block { }; // When running outside of loom, this calls `spin_loop_hint`. - loom::yield_now(); + thread::yield_now(); } } } diff --git a/tokio-sync/src/mpsc/list.rs b/tokio-sync/src/mpsc/list.rs index 595af88fc..b3019a51e 100644 --- a/tokio-sync/src/mpsc/list.rs +++ b/tokio-sync/src/mpsc/list.rs @@ -2,8 +2,8 @@ use super::block::{self, Block}; use crate::loom::{ - self, sync::atomic::{AtomicPtr, AtomicUsize}, + thread, }; use std::fmt; use std::ptr::NonNull; @@ -163,7 +163,7 @@ impl Tx { block_ptr = next_block.as_ptr(); - loom::yield_now(); + thread::yield_now(); } } @@ -270,7 +270,7 @@ impl Rx { self.head = next_block; - loom::yield_now(); + thread::yield_now(); } } @@ -308,7 +308,7 @@ impl Rx { tx.reclaim_block(block); } - loom::yield_now(); + thread::yield_now(); } } diff --git a/tokio-sync/src/semaphore.rs b/tokio-sync/src/semaphore.rs index 4dcfddb99..6bfe4310c 100644 --- a/tokio-sync/src/semaphore.rs +++ b/tokio-sync/src/semaphore.rs @@ -14,7 +14,7 @@ use crate::loom::{ atomic::{AtomicPtr, AtomicUsize}, CausalCell, }, - yield_now, + thread, }; use std::fmt; @@ -432,7 +432,7 @@ impl Semaphore { if curr.has_waiter(&self.stub) { // Inconsistent debug!(" + pop; inconsistent 1"); - yield_now(); + thread::yield_now(); continue 'outer; } @@ -479,7 +479,7 @@ impl Semaphore { if tail != head { // Inconsistent debug!(" + pop; inconsistent 2"); - yield_now(); + thread::yield_now(); continue 'outer; } @@ -495,7 +495,7 @@ impl Semaphore { // Inconsistent state, loop debug!(" + pop; inconsistent 3"); - yield_now(); + thread::yield_now(); } } } diff --git a/tokio-sync/tests/fuzz_list.rs b/tokio-sync/tests/fuzz_list.rs index acfc6109d..e0a55473d 100644 --- a/tokio-sync/tests/fuzz_list.rs +++ b/tokio-sync/tests/fuzz_list.rs @@ -63,7 +63,7 @@ fn smoke() { } None => { debug!(" + pop() -> None"); - loom::yield_now(); + thread::yield_now(); } } }