diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-04 22:22:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-04 22:22:40 -0800 |
commit | a6253ed05a1e0d14bc64915f5937c29092df9497 (patch) | |
tree | 15c96ca9b66e5bca424769e8c715f732feaa1b1c /tokio/src/sync | |
parent | 94f9b04b066cfc3da5c3ee2c961c21a9496135dd (diff) |
chore: unify all mocked `loom` files (#1732)
When the crates were merged, each component kept its own `loom` file
containing mocked types it needed. This patch unifies them all in one
location.
Diffstat (limited to 'tokio/src/sync')
-rw-r--r-- | tokio/src/sync/loom.rs | 48 | ||||
-rw-r--r-- | tokio/src/sync/mod.rs | 2 | ||||
-rw-r--r-- | tokio/src/sync/mpsc/block.rs | 4 | ||||
-rw-r--r-- | tokio/src/sync/mpsc/chan.rs | 6 | ||||
-rw-r--r-- | tokio/src/sync/mpsc/list.rs | 2 | ||||
-rw-r--r-- | tokio/src/sync/mpsc/unbounded.rs | 2 | ||||
-rw-r--r-- | tokio/src/sync/oneshot.rs | 4 | ||||
-rw-r--r-- | tokio/src/sync/semaphore.rs | 8 | ||||
-rw-r--r-- | tokio/src/sync/task/atomic_waker.rs | 4 |
9 files changed, 13 insertions, 67 deletions
diff --git a/tokio/src/sync/loom.rs b/tokio/src/sync/loom.rs deleted file mode 100644 index 1b5a5c9d..00000000 --- a/tokio/src/sync/loom.rs +++ /dev/null @@ -1,48 +0,0 @@ -#[cfg(not(all(test, loom)))] -mod imp { - pub(crate) mod future { - pub(crate) use crate::sync::task::AtomicWaker; - } - - pub(crate) mod sync { - pub(crate) use std::sync::atomic; - pub(crate) use std::sync::Arc; - - use std::cell::UnsafeCell; - - pub(crate) struct CausalCell<T>(UnsafeCell<T>); - - impl<T> CausalCell<T> { - pub(crate) fn new(data: T) -> CausalCell<T> { - CausalCell(UnsafeCell::new(data)) - } - - pub(crate) fn with<F, R>(&self, f: F) -> R - where - F: FnOnce(*const T) -> R, - { - f(self.0.get()) - } - - pub(crate) fn with_mut<F, R>(&self, f: F) -> R - where - F: FnOnce(*mut T) -> R, - { - f(self.0.get()) - } - } - } - - pub(crate) mod thread { - pub(crate) fn yield_now() { - ::std::sync::atomic::spin_loop_hint(); - } - } -} - -#[cfg(all(test, loom))] -mod imp { - pub(crate) use loom::*; -} - -pub(crate) use self::imp::*; diff --git a/tokio/src/sync/mod.rs b/tokio/src/sync/mod.rs index 84f6bd98..25f58ffd 100644 --- a/tokio/src/sync/mod.rs +++ b/tokio/src/sync/mod.rs @@ -37,8 +37,6 @@ macro_rules! if_loom { mod barrier; pub use barrier::{Barrier, BarrierWaitResult}; -mod loom; - pub mod mpsc; mod mutex; diff --git a/tokio/src/sync/mpsc/block.rs b/tokio/src/sync/mpsc/block.rs index aea69384..f03648ba 100644 --- a/tokio/src/sync/mpsc/block.rs +++ b/tokio/src/sync/mpsc/block.rs @@ -1,6 +1,6 @@ -use crate::sync::loom::{ +use crate::loom::{ + cell::CausalCell, sync::atomic::{AtomicPtr, AtomicUsize}, - sync::CausalCell, thread, }; diff --git a/tokio/src/sync/mpsc/chan.rs b/tokio/src/sync/mpsc/chan.rs index fe5ff904..ad0d99a8 100644 --- a/tokio/src/sync/mpsc/chan.rs +++ b/tokio/src/sync/mpsc/chan.rs @@ -1,8 +1,4 @@ -use crate::sync::loom::{ - future::AtomicWaker, - sync::atomic::AtomicUsize, - sync::{Arc, CausalCell}, -}; +use crate::loom::{cell::CausalCell, future::AtomicWaker, sync::atomic::AtomicUsize, sync::Arc}; use crate::sync::mpsc::list; use std::fmt; diff --git a/tokio/src/sync/mpsc/list.rs b/tokio/src/sync/mpsc/list.rs index a1295bb0..eecc4da3 100644 --- a/tokio/src/sync/mpsc/list.rs +++ b/tokio/src/sync/mpsc/list.rs @@ -1,6 +1,6 @@ //! A concurrent, lock-free, FIFO list. -use crate::sync::loom::{ +use crate::loom::{ sync::atomic::{AtomicPtr, AtomicUsize}, thread, }; diff --git a/tokio/src/sync/mpsc/unbounded.rs b/tokio/src/sync/mpsc/unbounded.rs index 5a73771e..4eb750ef 100644 --- a/tokio/src/sync/mpsc/unbounded.rs +++ b/tokio/src/sync/mpsc/unbounded.rs @@ -1,4 +1,4 @@ -use crate::sync::loom::sync::atomic::AtomicUsize; +use crate::loom::sync::atomic::AtomicUsize; use crate::sync::mpsc::chan; use std::fmt; diff --git a/tokio/src/sync/oneshot.rs b/tokio/src/sync/oneshot.rs index 7cf4eb8f..3c757e9e 100644 --- a/tokio/src/sync/oneshot.rs +++ b/tokio/src/sync/oneshot.rs @@ -1,6 +1,8 @@ //! A channel for sending a single message between asynchronous tasks. -use crate::sync::loom::sync::{atomic::AtomicUsize, Arc, CausalCell}; +use crate::loom::cell::CausalCell; +use crate::loom::sync::atomic::AtomicUsize; +use crate::loom::sync::Arc; use futures_core::ready; use std::fmt; diff --git a/tokio/src/sync/semaphore.rs b/tokio/src/sync/semaphore.rs index 1120be07..b4a093f8 100644 --- a/tokio/src/sync/semaphore.rs +++ b/tokio/src/sync/semaphore.rs @@ -8,12 +8,10 @@ //! section. If no permits are available, then acquiring the semaphore returns //! `Pending`. The task is woken once a permit becomes available. -use crate::sync::loom::{ +use crate::loom::{ + cell::CausalCell, future::AtomicWaker, - sync::{ - atomic::{AtomicPtr, AtomicUsize}, - CausalCell, - }, + sync::atomic::{AtomicPtr, AtomicUsize}, thread, }; diff --git a/tokio/src/sync/task/atomic_waker.rs b/tokio/src/sync/task/atomic_waker.rs index ff952a18..88d083d6 100644 --- a/tokio/src/sync/task/atomic_waker.rs +++ b/tokio/src/sync/task/atomic_waker.rs @@ -1,5 +1,5 @@ -use crate::sync::loom::sync::atomic::{self, AtomicUsize}; -use crate::sync::loom::sync::CausalCell; +use crate::loom::cell::CausalCell; +use crate::loom::sync::atomic::{self, AtomicUsize}; use std::fmt; use std::sync::atomic::Ordering::{AcqRel, Acquire, Release}; |