diff options
author | Lucio Franco <luciofranco14@gmail.com> | 2020-10-12 13:44:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 13:44:54 -0400 |
commit | 8880222036f37c6204c8466f25e828447f16dacb (patch) | |
tree | fd623afc20f73bbce65746a3d1b1b2731ecf30a5 | |
parent | 0893841f31542b2b04c5050a8a4a3c45cf867e55 (diff) |
rt: Remove `threaded_scheduler()` and `basic_scheduler()` (#2876)
Co-authored-by: Alice Ryhl <alice@ryhl.io>
Co-authored-by: Carl Lerche <me@carllerche.com>
90 files changed, 1469 insertions, 1687 deletions
diff --git a/benches/mpsc.rs b/benches/mpsc.rs index 2f3fe963..3f7e3fca 100644 --- a/benches/mpsc.rs +++ b/benches/mpsc.rs @@ -4,6 +4,13 @@ use tokio::sync::mpsc; type Medium = [usize; 64]; type Large = [Medium; 64]; +fn rt() -> tokio::runtime::Runtime { + tokio::runtime::Builder::new_multi_thread() + .worker_threads(6) + .build() + .unwrap() +} + fn create_1_medium(b: &mut Bencher) { b.iter(|| { black_box(&mpsc::channel::<Medium>(1)); @@ -43,11 +50,7 @@ fn send_large(b: &mut Bencher) { } fn contention_bounded(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() - .build() - .unwrap(); + let rt = rt(); b.iter(|| { rt.block_on(async move { @@ -70,11 +73,7 @@ fn contention_bounded(b: &mut Bencher) { } fn contention_bounded_full(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() - .build() - .unwrap(); + let rt = rt(); b.iter(|| { rt.block_on(async move { @@ -97,11 +96,7 @@ fn contention_bounded_full(b: &mut Bencher) { } fn contention_unbounded(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() - .build() - .unwrap(); + let rt = rt(); b.iter(|| { rt.block_on(async move { @@ -124,11 +119,7 @@ fn contention_unbounded(b: &mut Bencher) { } fn uncontented_bounded(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() - .build() - .unwrap(); + let rt = rt(); b.iter(|| { rt.block_on(async move { @@ -146,11 +137,7 @@ fn uncontented_bounded(b: &mut Bencher) { } fn uncontented_unbounded(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() - .build() - .unwrap(); + let rt = rt(); b.iter(|| { rt.block_on(async move { diff --git a/benches/scheduler.rs b/benches/scheduler.rs index 801de72a..68a6d6a4 100644 --- a/benches/scheduler.rs +++ b/benches/scheduler.rs @@ -139,9 +139,8 @@ fn chained_spawn(b: &mut Bencher) { } fn rt() -> Runtime { - runtime::Builder::new() - .threaded_scheduler() - .core_threads(4) + runtime::Builder::new_multi_thread() + .worker_threads(4) .enable_all() .build() .unwrap() diff --git a/benches/signal.rs b/benches/signal.rs index 3a354c6b..fcad40da 100644 --- a/benches/signal.rs +++ b/benches/signal.rs @@ -45,9 +45,9 @@ fn many_signals(bench: &mut Bencher) { let num_signals = 10; let (tx, mut rx) = mpsc::channel(num_signals); - let rt = runtime::Builder::new() + let rt = runtime::Builder::new_multi_thread() // Intentionally single threaded to measure delays in propagating wakes - .basic_scheduler() + .worker_threads(0) .enable_all() .build() .unwrap(); diff --git a/benches/spawn.rs b/benches/spawn.rs index f76daf3f..72a40357 100644 --- a/benches/spawn.rs +++ b/benches/spawn.rs @@ -10,8 +10,7 @@ async fn work() -> usize { } fn basic_scheduler_local_spawn(bench: &mut Bencher) { - let runtime = tokio::runtime::Builder::new() - .basic_scheduler() + let runtime = tokio::runtime::Builder::new_current_thread() .build() .unwrap(); runtime.block_on(async { @@ -23,8 +22,7 @@ fn basic_scheduler_local_spawn(bench: &mut Bencher) { } fn threaded_scheduler_local_spawn(bench: &mut Bencher) { - let runtime = tokio::runtime::Builder::new() - .threaded_scheduler() + let runtime = tokio::runtime::Builder::new_current_thread() .build() .unwrap(); runtime.block_on(async { @@ -36,8 +34,7 @@ fn threaded_scheduler_local_spawn(bench: &mut Bencher) { } fn basic_scheduler_remote_spawn(bench: &mut Bencher) { - let runtime = tokio::runtime::Builder::new() - .basic_scheduler() + let runtime = tokio::runtime::Builder::new_current_thread() .build() .unwrap(); @@ -48,10 +45,7 @@ fn basic_scheduler_remote_spawn(bench: &mut Bencher) { } fn threaded_scheduler_remote_spawn(bench: &mut Bencher) { - let runtime = tokio::runtime::Builder::new() - .threaded_scheduler() - .build() - .unwrap(); + let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap(); bench.iter(|| { let h = runtime.spawn(work()); diff --git a/benches/sync_rwlock.rs b/benches/sync_rwlock.rs index 30c66e49..46eeac0c 100644 --- a/benches/sync_rwlock.rs +++ b/benches/sync_rwlock.rs @@ -3,9 +3,8 @@ use std::sync::Arc; use tokio::{sync::RwLock, task}; fn read_uncontended(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(6) .build() .unwrap(); @@ -22,9 +21,8 @@ fn read_uncontended(b: &mut Bencher) { } fn read_concurrent_uncontended_multi(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(6) .build() .unwrap(); @@ -51,8 +49,7 @@ fn read_concurrent_uncontended_multi(b: &mut Bencher) { } fn read_concurrent_uncontended(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .basic_scheduler() + let rt = tokio::runtime::Builder::new_current_thread() .build() .unwrap(); @@ -78,9 +75,8 @@ fn read_concurrent_uncontended(b: &mut Bencher) { } fn read_concurrent_contended_multi(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(6) .build() .unwrap(); @@ -108,8 +104,7 @@ fn read_concurrent_contended_multi(b: &mut Bencher) { } fn read_concurrent_contended(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .basic_scheduler() + let rt = tokio::runtime::Builder::new_current_thread() .build() .unwrap(); diff --git a/benches/sync_semaphore.rs b/benches/sync_semaphore.rs index 32d4aa2b..19a1dd33 100644 --- a/benches/sync_semaphore.rs +++ b/benches/sync_semaphore.rs @@ -3,9 +3,8 @@ use std::sync::Arc; use tokio::{sync::Semaphore, task}; fn uncontended(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(6) .build() .unwrap(); @@ -27,9 +26,8 @@ async fn task(s: Arc<Semaphore>) { } fn uncontended_concurrent_multi(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(6) .build() .unwrap(); @@ -51,8 +49,8 @@ fn uncontended_concurrent_multi(b: &mut Bencher) { } fn uncontended_concurrent_single(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .basic_scheduler() + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(0) .build() .unwrap(); @@ -73,9 +71,8 @@ fn uncontended_concurrent_single(b: &mut Bencher) { } fn contended_concurrent_multi(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .core_threads(6) - .threaded_scheduler() + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(6) .build() .unwrap(); @@ -97,8 +94,7 @@ fn contended_concurrent_multi(b: &mut Bencher) { } fn contended_concurrent_single(b: &mut Bencher) { - let rt = tokio::runtime::Builder::new() - .basic_scheduler() + let rt = tokio::runtime::Builder::new_current_thread() .build() .unwrap(); diff --git a/tests-build/Cargo.toml b/tests-build/Cargo.toml index 68231d71..e76621b4 100644 --- a/tests-build/Cargo.toml +++ b/tests-build/Cargo.toml @@ -7,6 +7,7 @@ publish = false [features] full = ["tokio/full"] +rt-core = ["tokio/rt-core", "tokio/macros"] [dependencies] tokio = { path = "../tokio", optional = true } diff --git a/tests-build/tests/fail/macros_core_no_default.rs b/tests-build/tests/fail/macros_core_no_default.rs new file mode 100644 index 00000000..23f8847d --- /dev/null +++ b/tests-build/tests/fail/macros_core_no_default.rs @@ -0,0 +1,6 @@ +use tests_build::tokio; + +#[tokio::main] +async fn my_fn() {} + +fn main() {} diff --git a/tests-build/tests/fail/macros_core_no_default.stderr b/tests-build/tests/fail/macros_core_no_default.stderr new file mode 100644 index 00000000..a3ae32cd --- /dev/null +++ b/tests-build/tests/fail/macros_core_no_default.stderr @@ -0,0 +1,7 @@ +error: The default runtime flavor is `multi_thread`, but the `rt-threaded` feature is disabled. + --> $DIR/macros_core_no_default.rs:3:1 + | +3 | #[tokio::main] + | ^^^^^^^^^^^^^^ + | + = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr index 96fdcb17..4c68bd93 100644 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -4,7 +4,7 @@ error: the async keyword is missing from the function declaration 4 | fn main_is_not_async() {} | ^^ -error: Unknown attribute foo is specified; expected `basic_scheduler` or `threaded_scheduler` +error: Unknown attribute foo is specified; expected one of: `flavor`, `worker_threads` --> $DIR/macros_invalid_input.rs:6:15 | 6 | #[tokio::main(foo)] @@ -28,7 +28,7 @@ error: the test function cannot accept arguments 16 | async fn test_fn_has_args(_x: u8) {} | ^^^^^^ -error: Unknown attribute foo is specified; expected `basic_scheduler` or `threaded_scheduler` +error: Unknown attribute foo is specified; expected one of: `flavor`, `worker_threads` --> $DIR/macros_invalid_input.rs:18:15 | 18 | #[tokio::test(foo)] diff --git a/tests-build/tests/macros.rs b/tests-build/tests/macros.rs index 170db227..a12a20ef 100644 --- a/tests-build/tests/macros.rs +++ b/tests-build/tests/macros.rs @@ -1,9 +1,12 @@ #[test] -fn compile_fail() { +fn compile_fail_full() { let t = trybuild::TestCases::new(); #[cfg(feature = "full")] t.compile_fail("tests/fail/macros_invalid_input.rs"); + #[cfg(all(feature = "rt-core", not(feature = "full")))] + t.compile_fail("tests/fail/macros_core_no_default.rs"); + drop(t); } diff --git a/tests-integration/tests/macros_main.rs b/tests-integration/tests/macros_main.rs index 42f5be3b..868adb0f 100644 --- a/tests-integration/tests/macros_main.rs +++ b/tests-integration/tests/macros_main.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "macros")] +#![cfg(all(feature = "macros", feature = "rt-core"))] #[tokio::main] async fn basic_main() -> usize { @@ -10,18 +10,15 @@ async fn generic_fun<T: Default>() -> T { T::default() } -#[cfg(feature = "rt-core")] -mod spawn { - #[tokio::main] - async fn spawning() -> usize { - let join = tokio::spawn(async { 1 }); - join.await.unwrap() - } +#[tokio::main] +async fn spawning() -> usize { + let join = tokio::spawn(async { 1 }); + join.await.unwrap() +} - #[test] - fn main_with_spawn() { - assert_eq!(1, spawning()); - } +#[test] +fn main_with_spawn() { + assert_eq!(1, spawning()); } #[test] diff --git a/tests-integration/tests/rt_shell.rs b/tests-integration/tests/rt_shell.rs deleted file mode 100644 index 012f44a7..00000000 --- a/tests-integration/tests/rt_shell.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![warn(rust_2018_idioms)] -#![cfg(feature = "sync")] - -use tokio::runtime; -use tokio::sync::oneshot; - |