diff options
author | Taiki Endo <te316e89@gmail.com> | 2020-10-13 06:13:23 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 14:13:23 -0700 |
commit | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 (patch) | |
tree | e70838b9437123dc986ebcfeb8fc0c44ca3fe667 /tokio/src/runtime | |
parent | 24d0a0cfa8916eaef17f40f044d978aa3904d654 (diff) |
rt: simplify rt-* features (#2949)
tokio:
merge rt-core and rt-util as rt
rename rt-threaded to rt-multi-thread
tokio-util:
rename rt-core to rt
Closes #2942
Diffstat (limited to 'tokio/src/runtime')
-rw-r--r-- | tokio/src/runtime/builder.rs | 8 | ||||
-rw-r--r-- | tokio/src/runtime/context.rs | 2 | ||||
-rw-r--r-- | tokio/src/runtime/enter.rs | 12 | ||||
-rw-r--r-- | tokio/src/runtime/mod.rs | 30 | ||||
-rw-r--r-- | tokio/src/runtime/spawner.rs | 16 | ||||
-rw-r--r-- | tokio/src/runtime/task/core.rs | 2 | ||||
-rw-r--r-- | tokio/src/runtime/task/error.rs | 2 | ||||
-rw-r--r-- | tokio/src/runtime/task/join.rs | 2 | ||||
-rw-r--r-- | tokio/src/runtime/task/mod.rs | 8 |
9 files changed, 41 insertions, 41 deletions
diff --git a/tokio/src/runtime/builder.rs b/tokio/src/runtime/builder.rs index 27981d33..735e9b6a 100644 --- a/tokio/src/runtime/builder.rs +++ b/tokio/src/runtime/builder.rs @@ -73,7 +73,7 @@ pub(crate) type ThreadNameFn = std::sync::Arc<dyn Fn() -> String + Send + Sync + pub(crate) enum Kind { CurrentThread, - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] MultiThread, } @@ -84,7 +84,7 @@ impl Builder { } /// TODO - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] pub fn new_multi_thread() -> Builder { Builder::new(Kind::MultiThread) } @@ -365,7 +365,7 @@ impl Builder { pub fn build(&mut self) -> io::Result<Runtime> { match &self.kind { Kind::CurrentThread => self.build_basic_runtime(), - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] Kind::MultiThread => self.build_threaded_runtime(), } } @@ -477,7 +477,7 @@ cfg_time! { } } -cfg_rt_threaded! { +cfg_rt_multi_thread! { impl Builder { fn build_threaded_runtime(&mut self) -> io::Result<Runtime> { use crate::loom::sys::num_cpus; diff --git a/tokio/src/runtime/context.rs b/tokio/src/runtime/context.rs index e28d5282..9dfca8d8 100644 --- a/tokio/src/runtime/context.rs +++ b/tokio/src/runtime/context.rs @@ -48,7 +48,7 @@ cfg_time! { } } -cfg_rt_core! { +cfg_rt! { pub(crate) fn spawn_handle() -> Option<crate::runtime::Spawner> { CONTEXT.with(|ctx| match *ctx.borrow() { Some(ref ctx) => Some(ctx.spawner.clone()), diff --git a/tokio/src/runtime/enter.rs b/tokio/src/runtime/enter.rs index 79ed4d17..4dd8dd01 100644 --- a/tokio/src/runtime/enter.rs +++ b/tokio/src/runtime/enter.rs @@ -4,7 +4,7 @@ use std::marker::PhantomData; #[derive(Debug, Clone, Copy)] pub(crate) enum EnterContext { - #[cfg_attr(not(feature = "rt-core"), allow(dead_code))] + #[cfg_attr(not(feature = "rt"), allow(dead_code))] Entered { allow_blocking: bool, }, @@ -24,7 +24,7 @@ pub(crate) struct Enter { _p: PhantomData<RefCell<()>>, } -cfg_rt_core! { +cfg_rt! { use crate::park::thread::ParkError; use std::time::Duration; @@ -65,7 +65,7 @@ cfg_rt_core! { // // This is hidden for a reason. Do not use without fully understanding // executors. Misuing can easily cause your program to deadlock. -cfg_rt_threaded! { +cfg_rt_multi_thread! { pub(crate) fn exit<F: FnOnce() -> R, R>(f: F) -> R { // Reset in case the closure panics struct Reset(EnterContext); @@ -91,7 +91,7 @@ cfg_rt_threaded! { } } -cfg_rt_util! { +cfg_rt! { /// Disallow blocking in the current runtime context until the guard is dropped. pub(crate) fn disallow_blocking() -> DisallowBlockingGuard { let reset = ENTERED.with(|c| { @@ -130,14 +130,14 @@ cfg_rt_util! { } } -cfg_rt_threaded! { +cfg_rt_multi_thread! { /// Returns true if in a runtime context. pub(crate) fn context() -> EnterContext { ENTERED.with(|c| c.get()) } } -cfg_rt_core! { +cfg_rt! { impl Enter { /// Blocks the thread on the specified future, returning the value with /// which that future completes. diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index c79a942f..7712a7f8 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -114,7 +114,7 @@ //! //! The current-thread scheduler provides a _single-threaded_ future executor. //! All tasks will be created and executed on the current thread. This requires -//! the `rt-core` feature flag. +//! the `rt` feature flag. //! ``` //! use tokio::runtime; //! @@ -129,7 +129,7 @@ //! The multi-thread scheduler executes futures on a _thread pool_, using a //! work-stealing strategy. By default, it will start a worker thread for each //! CPU core available on the system. This tends to be the ideal configurations -//! for most applications. The multi-thread scheduler requires the `rt-threaded` +//! for most applications. The multi-thread scheduler requires the `rt-multi-thread` //! feature flag, and is selected by default: //! ``` //! use tokio::runtime; @@ -181,7 +181,7 @@ pub(crate) mod enter; pub(crate) mod task; -cfg_rt_core! { +cfg_rt! { mod basic_scheduler; use basic_scheduler::BasicScheduler; @@ -204,19 +204,19 @@ cfg_rt_core! { use self::spawner::Spawner; } -cfg_rt_threaded! { +cfg_rt_multi_thread! { mod park; use park::Parker; } -cfg_rt_threaded! { +cfg_rt_multi_thread! { mod queue; pub(crate) mod thread_pool; use self::thread_pool::ThreadPool; } -cfg_rt_core! { +cfg_rt! { use crate::task::JoinHandle; use std::future::Future; @@ -266,11 +266,11 @@ cfg_rt_core! { #[derive(Debug)] enum Kind { /// Execute all tasks on the current-thread. - #[cfg(feature = "rt-core")] + #[cfg(feature = "rt")] CurrentThread(BasicScheduler<driver::Driver>), /// Execute tasks across multiple threads. - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] ThreadPool(ThreadPool), } @@ -282,8 +282,8 @@ cfg_rt_core! { /// /// This results in a scheduler, I/O driver, and time driver being /// initialized. The type of scheduler used depends on what feature flags - /// are enabled: if the `rt-threaded` feature is enabled, the [threaded - /// scheduler] is used, while if only the `rt-core` feature is enabled, the + /// are enabled: if the `rt-multi-thread` feature is enabled, the [threaded + /// scheduler] is used, while if only the `rt` feature is enabled, the /// [basic scheduler] is used instead. /// /// If the threaded scheduler is selected, it will not spawn @@ -313,7 +313,7 @@ cfg_rt_core! { /// [threaded scheduler]: index.html#threaded-scheduler /// [basic scheduler]: index.html#basic-scheduler /// [runtime builder]: crate::runtime::Builder - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] pub fn new() -> std::io::Result<Runtime> { Builder::new_multi_thread().enable_all().build() } @@ -343,14 +343,14 @@ cfg_rt_core! { /// }); /// # } /// ``` - #[cfg(feature = "rt-core")] + #[cfg(feature = "rt")] pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> where F: Future + Send + 'static, F::Output: Send + 'static, { match &self.kind { - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] Kind::ThreadPool(exec) => exec.spawn(future), Kind::CurrentThread(exec) => exec.spawn(future), } @@ -393,9 +393,9 @@ cfg_rt_core! { /// [handle]: fn@Handle::block_on pub fn block_on<F: Future>(&self, future: F) -> F::Output { self.handle.enter(|| match &self.kind { - #[cfg(feature = "rt-core")] + #[cfg(feature = "rt")] Kind::CurrentThread(exec) => exec.block_on(future), - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] Kind::ThreadPool(exec) => exec.block_on(future), }) } diff --git a/tokio/src/runtime/spawner.rs b/tokio/src/runtime/spawner.rs index 28ff7c04..a37c6679 100644 --- a/tokio/src/runtime/spawner.rs +++ b/tokio/src/runtime/spawner.rs @@ -1,25 +1,25 @@ -cfg_rt_core! { +cfg_rt! { use crate::runtime::basic_scheduler; use crate::task::JoinHandle; use std::future::Future; } -cfg_rt_threaded! { +cfg_rt_multi_thread! { use crate::runtime::thread_pool; } #[derive(Debug, Clone)] pub(crate) enum Spawner { - #[cfg(feature = "rt-core")] + #[cfg(feature = "rt")] Basic(basic_scheduler::Spawner), - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] ThreadPool(thread_pool::Spawner), } impl Spawner { pub(crate) fn shutdown(&mut self) { - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] { if let Spawner::ThreadPool(spawner) = self { spawner.shutdown(); @@ -28,7 +28,7 @@ impl Spawner { } } -cfg_rt_core! { +cfg_rt! { impl Spawner { pub(crate) fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> where @@ -36,9 +36,9 @@ cfg_rt_core! { F::Output: Send + 'static, { match self { - #[cfg(feature = "rt-core")] + #[cfg(feature = "rt")] Spawner::Basic(spawner) => spawner.spawn(future), - #[cfg(feature = "rt-threaded")] + #[cfg(feature = "rt-multi-thread")] Spawner::ThreadPool(spawner) => spawner.spawn(future), } } diff --git a/tokio/src/runtime/task/core.rs b/tokio/src/runtime/task/core.rs index f4756c23..dfa87641 100644 --- a/tokio/src/runtime/task/core.rs +++ b/tokio/src/runtime/task/core.rs @@ -269,7 +269,7 @@ impl<T: Future, S: Schedule> Core<T, S> { } } -cfg_rt_threaded! { +cfg_rt_multi_thread! { impl Header { pub(crate) fn shutdown(&self) { use crate::runtime::task::RawTask; diff --git a/tokio/src/runtime/task/error.rs b/tokio/src/runtime/task/error.rs index 4197ba60..177fe65e 100644 --- a/tokio/src/runtime/task/error.rs +++ b/tokio/src/runtime/task/error.rs @@ -3,7 +3,7 @@ use std::fmt; use std::io; use std::sync::Mutex; -cfg_task! { +cfg_rt! { /// Task failed to execute to completion. pub struct JoinError { repr: Repr, diff --git a/tokio/src/runtime/task/join.rs b/tokio/src/runtime/task/join.rs index a63f5740..dedfb387 100644 --- a/tokio/src/runtime/task/join.rs +++ b/tokio/src/runtime/task/join.rs @@ -6,7 +6,7 @@ use std::marker::PhantomData; use std::pin::Pin; use std::task::{Context, Poll}; -cfg_task! { +cfg_rt! { /// An owned permission to join on a task (await its termination). /// /// This can be thought of as the equivalent of [`std::thread::JoinHandle`] for diff --git a/tokio/src/runtime/task/mod.rs b/tokio/src/runtime/task/mod.rs index d30a467f..7b49e95a 100644 --- a/tokio/src/runtime/task/mod.rs +++ b/tokio/src/runtime/task/mod.rs @@ -21,7 +21,7 @@ use self::state::State; mod waker; -cfg_rt_threaded! { +cfg_rt_multi_thread! { mod stack; pub(crate) use self::stack::TransferStack; } @@ -79,7 +79,7 @@ pub(crate) trait Schedule: Sync + Sized + 'static { } } -cfg_rt_core! { +cfg_rt! { /// Create a new task with an associated join handle pub(crate) fn joinable<T, S>(task: T) -> (Notified<S>, JoinHandle<T::Output>) where @@ -99,7 +99,7 @@ cfg_rt_core! { } } -cfg_rt_util! { +cfg_rt! { /// Create a new `!Send` task with an associated join handle pub(crate) unsafe fn joinable_local<T, S>(task: T) -> (Notified<S>, JoinHandle<T::Output>) where @@ -132,7 +132,7 @@ impl<S: 'static> Task<S> { } } -cfg_rt_threaded! { +cfg_rt_multi_thread! { impl<S: 'static> Notified<S> { pub(crate) unsafe fn from_raw(ptr: NonNull<Header>) -> Notified<S> { Notified(Task::from_raw(ptr)) |