diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-01 13:18:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-01 13:18:52 -0700 |
commit | d70c928d88dff9e3e8d673b8ee02bce131598550 (patch) | |
tree | 6b079db2f80bd61764203a32ffe48769d18c1386 /tokio/src/executor/loom/std/mod.rs | |
parent | 742d89b0f333150f6a550ae7840235851f4eb069 (diff) |
runtime: merge multi & single threaded runtimes (#1716)
Simplify Tokio's runtime construct by combining both Runtime variants
into a single type. The execution style can be controlled by a
configuration setting on `Builder`.
The implication of this change is that there is no longer any way to
spawn `!Send` futures. This, however, is a temporary limitation. A
different strategy will be employed for supporting `!Send` futures.
Included in this patch is a rework of `task::JoinHandle` to support
using this type from both the thread-pool and current-thread executors.
Diffstat (limited to 'tokio/src/executor/loom/std/mod.rs')
-rw-r--r-- | tokio/src/executor/loom/std/mod.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/tokio/src/executor/loom/std/mod.rs b/tokio/src/executor/loom/std/mod.rs index 568912bf..eb865d98 100644 --- a/tokio/src/executor/loom/std/mod.rs +++ b/tokio/src/executor/loom/std/mod.rs @@ -1,10 +1,12 @@ +// rt-full implies rt-current-thread + #[cfg(feature = "rt-full")] mod atomic_u32; mod atomic_usize; -#[cfg(feature = "rt-full")] +#[cfg(feature = "rt-current-thread")] mod causal_cell; -#[cfg(feature = "rt-full")] +#[cfg(feature = "rt-current-thread")] pub(crate) mod alloc { #[derive(Debug)] pub(crate) struct Track<T> { @@ -26,7 +28,7 @@ pub(crate) mod alloc { } } -#[cfg(feature = "rt-full")] +#[cfg(feature = "rt-current-thread")] pub(crate) mod cell { pub(crate) use super::causal_cell::{CausalCell, CausalCheck}; } @@ -62,15 +64,23 @@ pub(crate) mod sync { pub(crate) use crate::executor::loom::std::atomic_usize::AtomicUsize; #[cfg(feature = "rt-full")] - pub(crate) use std::sync::atomic::{fence, spin_loop_hint, AtomicPtr}; + pub(crate) use std::sync::atomic::spin_loop_hint; + #[cfg(feature = "rt-current-thread")] + pub(crate) use std::sync::atomic::{fence, AtomicPtr}; } } -#[cfg(feature = "rt-full")] +#[cfg(feature = "rt-current-thread")] pub(crate) mod sys { + #[cfg(feature = "rt-full")] pub(crate) fn num_cpus() -> usize { usize::max(1, num_cpus::get_physical()) } + + #[cfg(not(feature = "rt-full"))] + pub(crate) fn num_cpus() -> usize { + 1 + } } #[cfg(any(feature = "blocking", feature = "rt-full"))] |