diff options
author | Carl Lerche <me@carllerche.com> | 2019-10-28 21:40:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-28 21:40:29 -0700 |
commit | c62ef2d232dea1535a8e22484fa2ca083f03e903 (patch) | |
tree | 40cacadf882433fa22a87c4911e160581b596ed8 /tokio/src/executor/loom/std/causal_cell.rs | |
parent | 7eb264a0d0ee68433b20ecafabed53a70a9d43a4 (diff) |
executor: move into `tokio` crate (#1702)
A step towards collapsing Tokio sub crates into a single `tokio`
crate (#1318).
The executor implementation is now provided by the main `tokio` crate.
Functionality can be opted out of by using the various net related
feature flags.
Diffstat (limited to 'tokio/src/executor/loom/std/causal_cell.rs')
-rw-r--r-- | tokio/src/executor/loom/std/causal_cell.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tokio/src/executor/loom/std/causal_cell.rs b/tokio/src/executor/loom/std/causal_cell.rs new file mode 100644 index 00000000..8247788d --- /dev/null +++ b/tokio/src/executor/loom/std/causal_cell.rs @@ -0,0 +1,48 @@ +use std::cell::UnsafeCell; + +pub(crate) struct CausalCell<T>(UnsafeCell<T>); + +#[derive(Default)] +pub(crate) struct CausalCheck(()); + +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_unchecked<F, R>(&self, f: F) -> R + where + F: FnOnce(*const T) -> R, + { + f(self.0.get()) + } + + pub(crate) fn check(&self) {} + + pub(crate) fn with_deferred<F, R>(&self, f: F) -> (R, CausalCheck) + where + F: FnOnce(*const T) -> R, + { + (f(self.0.get()), CausalCheck::default()) + } + + pub(crate) fn with_mut<F, R>(&self, f: F) -> R + where + F: FnOnce(*mut T) -> R, + { + f(self.0.get()) + } +} + +impl CausalCheck { + pub(crate) fn check(self) {} + + pub(crate) fn join(&mut self, _other: CausalCheck) {} +} |