Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rt: Switch rt-threaded to rt-multi-thread #2948

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -110,7 +110,7 @@ jobs:
rm -rf tokio/tests

- name: miri
run: cargo miri test --features rt-core,rt-threaded,rt-util,sync task
run: cargo miri test --features rt-core,rt-multi-thread,rt-util,sync task
working-directory: tokio

cross:
Expand Down
2 changes: 1 addition & 1 deletion tests-build/tests/fail/macros_core_no_default.stderr
@@ -1,4 +1,4 @@
error: The default runtime flavor is `multi_thread`, but the `rt-threaded` feature is disabled.
error: The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled.
--> $DIR/macros_core_no_default.rs:3:1
|
3 | #[tokio::main]
Expand Down
4 changes: 2 additions & 2 deletions tests-integration/Cargo.toml
Expand Up @@ -9,15 +9,15 @@ publish = false
full = [
"macros",
"rt-core",
"rt-threaded",
"rt-multi-thread",

"tokio/full",
"tokio-test"
]
macros = ["tokio/macros"]
sync = ["tokio/sync"]
rt-core = ["tokio/rt-core"]
rt-threaded = ["rt-core", "tokio/rt-threaded"]
rt-multi-thread = ["rt-core", "tokio/rt-multi-thread"]

[dependencies]
tokio = { path = "../tokio" }
Expand Down
4 changes: 2 additions & 2 deletions tokio-macros/src/entry.rs
Expand Up @@ -97,9 +97,9 @@ impl Configuration {
}),
(Threaded, _) => {
let msg = if self.flavor.is_none() {
"The default runtime flavor is `multi_thread`, but the `rt-threaded` feature is disabled."
"The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled."
} else {
"The runtime flavor `multi_thread` requires the `rt-threaded` feature."
"The runtime flavor `multi_thread` requires the `rt-multi-thread` feature."
};
Err(syn::Error::new(Span::call_site(), msg))
}
Expand Down
8 changes: 4 additions & 4 deletions tokio-macros/src/lib.rs
Expand Up @@ -258,27 +258,27 @@ pub fn test_rt_core(args: TokenStream, item: TokenStream) -> TokenStream {

/// Always fails with the error message below.
/// ```text
/// The #[tokio::main] macro requires rt-core or rt-threaded.
/// The #[tokio::main] macro requires rt-core or rt-multi-thread.
/// ```
#[proc_macro_attribute]
pub fn main_fail(_args: TokenStream, _item: TokenStream) -> TokenStream {
syn::Error::new(
proc_macro2::Span::call_site(),
"The #[tokio::main] macro requires rt-core or rt-threaded.",
"The #[tokio::main] macro requires rt-core or rt-multi-thread.",
)
.to_compile_error()
.into()
}

/// Always fails with the error message below.
/// ```text
/// The #[tokio::test] macro requires rt-core or rt-threaded.
/// The #[tokio::test] macro requires rt-core or rt-multi-thread.
/// ```
#[proc_macro_attribute]
pub fn test_fail(_args: TokenStream, _item: TokenStream) -> TokenStream {
syn::Error::new(
proc_macro2::Span::call_site(),
"The #[tokio::test] macro requires rt-core or rt-threaded.",
"The #[tokio::test] macro requires rt-core or rt-multi-thread.",
)
.to_compile_error()
.into()
Expand Down
4 changes: 2 additions & 2 deletions tokio/Cargo.toml
Expand Up @@ -39,7 +39,7 @@ full = [
"process",
"rt-core",
"rt-util",
"rt-threaded",
"rt-multi-thread",
"signal",
"stream",
"sync",
Expand All @@ -65,7 +65,7 @@ process = [
# Includes basic task execution capabilities
rt-core = ["slab"]
rt-util = []
rt-threaded = [
rt-multi-thread = [
"num_cpus",
"rt-core",
]
Expand Down
8 changes: 4 additions & 4 deletions tokio/src/lib.rs
Expand Up @@ -74,7 +74,7 @@
//!
//! - `full`: Enables all Tokio public API features listed below.
//! - `rt-core`: Enables `tokio::spawn` and the basic (single-threaded) scheduler.
//! - `rt-threaded`: Enables the heavier, multi-threaded, work-stealing scheduler.
//! - `rt-multi-thread`: Enables the heavier, multi-threaded, work-stealing scheduler.
//! - `rt-util`: Enables non-scheduler utilities.
//! - `io-util`: Enables the IO based `Ext` traits.
//! - `io-std`: Enable `Stdout`, `Stdin` and `Stderr` types.
Expand Down Expand Up @@ -199,9 +199,9 @@
//! and managing runtimes. You should use that module if the `#[tokio::main]` macro doesn't
//! provide the functionality you need.
//!
//! Using the runtime requires the "rt-core" or "rt-threaded" feature flags, to
//! Using the runtime requires the "rt-core" or "rt-multi-thread" feature flags, to
//! enable the basic [single-threaded scheduler][rt-core] and the [thread-pool
//! scheduler][rt-threaded], respectively. See the [`runtime` module
//! scheduler][rt-multi-thread], respectively. See the [`runtime` module
//! documentation][rt-features] for details. In addition, the "macros" feature
//! flag enables the `#[tokio::main]` and `#[tokio::test]` attributes.
//!
Expand All @@ -210,7 +210,7 @@
//! [`Builder`]: crate::runtime::Builder
//! [`Runtime`]: crate::runtime::Runtime
//! [rt-core]: runtime/index.html#basic-scheduler
//! [rt-threaded]: runtime/index.html#threaded-scheduler
//! [rt-multi-thread]: runtime/index.html#threaded-scheduler
//! [rt-features]: runtime/index.html#runtime-scheduler
//!
//! ## CPU-bound tasks and blocking code
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/loom/std/mod.rs
Expand Up @@ -81,12 +81,12 @@ pub(crate) mod sync {
}

pub(crate) mod sys {
#[cfg(feature = "rt-threaded")]
#[cfg(feature = "rt-multi-thread")]
pub(crate) fn num_cpus() -> usize {
usize::max(1, num_cpus::get())
}

#[cfg(not(feature = "rt-threaded"))]
#[cfg(not(feature = "rt-multi-thread"))]
pub(crate) fn num_cpus() -> usize {
1
}
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/macros/cfg.rs
Expand Up @@ -277,8 +277,8 @@ macro_rules! cfg_not_rt_core {
macro_rules! cfg_rt_threaded {
($($item:item)*) => {
$(
#[cfg(feature = "rt-threaded")]
#[cfg_attr(docsrs, doc(cfg(feature = "rt-threaded")))]
#[cfg(feature = "rt-multi-thread")]
#[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))]
$item
)*
}
Expand All @@ -296,7 +296,7 @@ macro_rules! cfg_rt_util {

macro_rules! cfg_not_rt_threaded {
($($item:item)*) => {
$( #[cfg(not(feature = "rt-threaded"))] $item )*
$( #[cfg(not(feature = "rt-multi-thread"))] $item )*
}
}

Expand Down
6 changes: 3 additions & 3 deletions tokio/src/runtime/builder.rs
Expand Up @@ -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,
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -366,7 +366,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(),
}
}
Expand Down
12 changes: 6 additions & 6 deletions tokio/src/runtime/mod.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -270,7 +270,7 @@ cfg_rt_core! {
CurrentThread(BasicScheduler<driver::Driver>),

/// Execute tasks across multiple threads.
#[cfg(feature = "rt-threaded")]
#[cfg(feature = "rt-multi-thread")]
ThreadPool(ThreadPool),
}

Expand All @@ -282,7 +282,7 @@ 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
/// are enabled: if the `rt-multi-thread` feature is enabled, the [threaded
/// scheduler] is used, while if only the `rt-core` feature is enabled, the
/// [basic scheduler] is used instead.
///
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -350,7 +350,7 @@ cfg_rt_core! {
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),
}
Expand Down Expand Up @@ -395,7 +395,7 @@ cfg_rt_core! {
self.handle.enter(|| match &self.kind {
#[cfg(feature = "rt-core")]
Kind::CurrentThread(exec) => exec.block_on(future),
#[cfg(feature = "rt-threaded")]
#[cfg(feature = "rt-multi-thread")]
Kind::ThreadPool(exec) => exec.block_on(future),
})
}
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/runtime/spawner.rs
Expand Up @@ -13,13 +13,13 @@ cfg_rt_threaded! {
pub(crate) enum Spawner {
#[cfg(feature = "rt-core")]
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();
Expand All @@ -38,7 +38,7 @@ cfg_rt_core! {
match self {
#[cfg(feature = "rt-core")]
Spawner::Basic(spawner) => spawner.spawn(future),
#[cfg(feature = "rt-threaded")]
#[cfg(feature = "rt-multi-thread")]
Spawner::ThreadPool(spawner) => spawner.spawn(future),
}
}
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/task/mod.rs
Expand Up @@ -159,7 +159,7 @@
//!
//! #### block_in_place
//!
//! When using the [threaded runtime][rt-threaded], the [`task::block_in_place`]
//! When using the [threaded runtime][rt-multi-thread], the [`task::block_in_place`]
//! function is also available. Like `task::spawn_blocking`, this function
//! allows running a blocking operation from an asynchronous context. Unlike
//! `spawn_blocking`, however, `block_in_place` works by transitioning the
Expand Down Expand Up @@ -211,7 +211,7 @@
//!
//! [`task::spawn_blocking`]: crate::task::spawn_blocking
//! [`task::block_in_place`]: crate::task::block_in_place
//! [rt-threaded]: ../runtime/index.html#threaded-scheduler
//! [rt-multi-thread]: ../runtime/index.html#threaded-scheduler
//! [`task::yield_now`]: crate::task::yield_now()
//! [`thread::yield_now`]: std::thread::yield_now

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/util/mod.rs
Expand Up @@ -16,7 +16,7 @@ cfg_io_driver! {
))]
pub(crate) mod linked_list;

#[cfg(any(feature = "rt-threaded", feature = "macros", feature = "stream"))]
#[cfg(any(feature = "rt-multi-thread", feature = "macros", feature = "stream"))]
mod rand;

cfg_rt_core! {
Expand Down