summaryrefslogtreecommitdiffstats
path: root/tokio/src/loom/std
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-11-12 15:23:40 -0800
committerGitHub <noreply@github.com>2019-11-12 15:23:40 -0800
commit27e5b41067d01c0c9fac230c5addb58034201a63 (patch)
treef9bd8333dfe1853dfe1d8710b4dc966bd8555d54 /tokio/src/loom/std
parente3df2eafd32e6f813d08617f0e2cd7abbc05c2b1 (diff)
reorganize modules (#1766)
This patch started as an effort to make `time::Timer` private. However, in an effort to get the build compiling again, more and more changes were made. This probably should have been broken up, but here we are. I will attempt to summarize the changes here. * Feature flags are reorganized to make clearer. `net-driver` becomes `io-driver`. `rt-current-thread` becomes `rt-core`. * The `Runtime` can be created without any executor. This replaces `enter`. It also allows creating I/O / time drivers that are standalone. * `tokio::timer` is renamed to `tokio::time`. This brings it in line with `std`. * `tokio::timer::Timer` is renamed to `Driver` and made private. * The `clock` module is removed. Instead, an `Instant` type is provided. This type defaults to calling `std::time::Instant`. A `test-util` feature flag can be used to enable hooking into time. * The `blocking` module is moved to the top level and is cleaned up. * The `task` module is moved to the top level. * The thread-pool's in-place blocking implementation is cleaned up. * `runtime::Spawner` is renamed to `runtime::Handle` and can be used to "enter" a runtime context.
Diffstat (limited to 'tokio/src/loom/std')
-rw-r--r--tokio/src/loom/std/atomic_u64.rs60
-rw-r--r--tokio/src/loom/std/mod.rs4
2 files changed, 62 insertions, 2 deletions
diff --git a/tokio/src/loom/std/atomic_u64.rs b/tokio/src/loom/std/atomic_u64.rs
new file mode 100644
index 00000000..206954fc
--- /dev/null
+++ b/tokio/src/loom/std/atomic_u64.rs
@@ -0,0 +1,60 @@
+//! Implementation of an atomic u64 cell. On 64 bit platforms, this is a
+//! re-export of `AtomicU64`. On 32 bit platforms, this is implemented using a
+//! `Mutex`.
+
+pub(crate) use self::imp::AtomicU64;
+
+// `AtomicU64` can only be used on targets with `target_has_atomic` is 64 or greater.
+// Once `cfg_target_has_atomic` feature is stable, we can replace it with
+// `#[cfg(target_has_atomic = "64")]`.
+// Refs: https://github.com/rust-lang/rust/tree/master/src/librustc_target
+#[cfg(not(any(target_arch = "arm", target_arch = "mips", target_arch = "powerpc")))]
+mod imp {
+ pub(crate) use std::sync::atomic::AtomicU64;
+}
+
+#[cfg(any(target_arch = "arm", target_arch = "mips", target_arch = "powerpc"))]
+mod imp {
+ use std::sync::atomic::Ordering;
+ use std::sync::Mutex;
+
+ #[derive(Debug)]
+ pub(crate) struct AtomicU64 {
+ inner: Mutex<u64>,
+ }
+
+ impl AtomicU64 {
+ pub(crate) fn new(val: u64) -> AtomicU64 {
+ AtomicU64 {
+ inner: Mutex::new(val),
+ }
+ }
+
+ pub(crate) fn load(&self, _: Ordering) -> u64 {
+ *self.inner.lock().unwrap()
+ }
+
+ pub(crate) fn store(&self, val: u64, _: Ordering) {
+ *self.inner.lock().unwrap() = val;
+ }
+
+ pub(crate) fn fetch_or(&self, val: u64, _: Ordering) -> u64 {
+ let mut lock = self.inner.lock().unwrap();
+ let prev = *lock;
+ *lock = prev | val;
+ prev
+ }
+
+ pub(crate) fn compare_and_swap(&self, old: u64, new: u64, _: Ordering) -> u64 {
+ let mut lock = self.inner.lock().unwrap();
+ let prev = *lock;
+
+ if prev != old {
+ return prev;
+ }
+
+ *lock = new;
+ prev
+ }
+ }
+}
diff --git a/tokio/src/loom/std/mod.rs b/tokio/src/loom/std/mod.rs
index e0aafa83..c5bd6039 100644
--- a/tokio/src/loom/std/mod.rs
+++ b/tokio/src/loom/std/mod.rs
@@ -1,8 +1,7 @@
-// rt-full implies rt-current-thread
-
#![cfg_attr(not(feature = "rt-full"), allow(unused_imports, dead_code))]
mod atomic_u32;
+mod atomic_u64;
mod atomic_usize;
mod causal_cell;
@@ -43,6 +42,7 @@ pub(crate) mod sync {
pub(crate) mod atomic {
pub(crate) use crate::loom::std::atomic_u32::AtomicU32;
+ pub(crate) use crate::loom::std::atomic_u64::AtomicU64;
pub(crate) use crate::loom::std::atomic_usize::AtomicUsize;
pub(crate) use std::sync::atomic::spin_loop_hint;