From c62ef2d232dea1535a8e22484fa2ca083f03e903 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Mon, 28 Oct 2019 21:40:29 -0700 Subject: [PATCH] executor: move into `tokio` crate (#1702) A step towards collapsing Tokio sub crates into a single `tokio` crate (#1318). The executor implementation is now provided by the main `tokio` crate. Functionality can be opted out of by using the various net related feature flags. --- Cargo.toml | 1 - azure-pipelines.yml | 39 +++---- ci/azure-tsan.yml | 2 - ci/patch.toml | 1 - tests-build/Cargo.toml | 3 +- tokio-executor/CHANGELOG.md | 81 -------------- tokio-executor/Cargo.toml | 52 --------- tokio-executor/LICENSE | 25 ----- tokio-executor/README.md | 13 --- tokio-executor/src/lib.rs | 102 ----------------- tokio-test/Cargo.toml | 1 - tokio-test/src/clock.rs | 2 +- tokio-test/src/task.rs | 2 +- tokio/Cargo.toml | 21 ++-- .../benches/thread_pool.rs | 2 +- tokio/src/executor.rs | 104 ------------------ .../src/executor}/blocking/builder.rs | 5 +- .../src/executor}/blocking/mod.rs | 10 +- .../src/executor}/current_thread/mod.rs | 18 +-- .../src/executor}/current_thread/scheduler.rs | 6 +- .../src => tokio/src/executor}/enter.rs | 2 +- .../src => tokio/src/executor}/error.rs | 0 .../src => tokio/src/executor}/executor.rs | 11 +- .../src => tokio/src/executor}/global.rs | 71 +++++++----- .../src => tokio/src/executor}/loom/mod.rs | 4 +- .../src/executor}/loom/std/atomic_u32.rs | 0 .../src/executor}/loom/std/atomic_usize.rs | 2 +- .../src/executor}/loom/std/causal_cell.rs | 0 .../src/executor}/loom/std/mod.rs | 22 ++-- tokio/src/executor/mod.rs | 84 ++++++++++++++ .../src => tokio/src/executor}/park/mod.rs | 0 .../src => tokio/src/executor}/park/thread.rs | 6 +- .../src => tokio/src/executor}/task/core.rs | 12 +- .../src => tokio/src/executor}/task/error.rs | 0 .../src/executor}/task/harness.rs | 10 +- .../src => tokio/src/executor}/task/join.rs | 4 +- .../src => tokio/src/executor}/task/list.rs | 2 +- .../src => tokio/src/executor}/task/mod.rs | 0 .../src => tokio/src/executor}/task/raw.rs | 10 +- .../src => tokio/src/executor}/task/stack.rs | 4 +- .../src => tokio/src/executor}/task/state.rs | 10 +- .../src/executor}/task/tests/loom.rs | 4 +- .../src/executor}/task/tests/mod.rs | 0 .../src/executor}/task/tests/task.rs | 11 +- .../src => tokio/src/executor}/task/waker.rs | 4 +- .../src/executor}/tests/backoff.rs | 0 .../src/executor}/tests/loom_oneshot.rs | 0 .../src/executor}/tests/loom_schedule.rs | 2 +- .../src/executor}/tests/mock_park.rs | 2 +- .../src/executor}/tests/mock_schedule.rs | 2 +- .../src => tokio/src/executor}/tests/mod.rs | 0 .../src/executor}/tests/track_drop.rs | 0 .../src/executor}/thread_pool/builder.rs | 30 ++--- .../src/executor}/thread_pool/current.rs | 6 +- .../src/executor}/thread_pool/idle.rs | 4 +- .../src/executor}/thread_pool/join.rs | 6 +- .../src/executor}/thread_pool/mod.rs | 2 +- .../src/executor}/thread_pool/owned.rs | 6 +- .../src/executor}/thread_pool/park.rs | 6 +- .../src/executor}/thread_pool/pool.rs | 14 +-- .../src/executor}/thread_pool/queue/global.rs | 6 +- .../src/executor}/thread_pool/queue/inject.rs | 6 +- .../src/executor}/thread_pool/queue/local.rs | 10 +- .../src/executor}/thread_pool/queue/mod.rs | 2 +- .../src/executor}/thread_pool/queue/worker.rs | 8 +- .../src/executor}/thread_pool/set.rs | 20 ++-- .../src/executor}/thread_pool/shared.rs | 6 +- .../src/executor}/thread_pool/shutdown.rs | 4 +- .../src/executor}/thread_pool/spawner.rs | 8 +- .../executor}/thread_pool/tests/loom_pool.rs | 12 +- .../executor}/thread_pool/tests/loom_queue.rs | 6 +- .../src/executor}/thread_pool/tests/mod.rs | 0 .../src/executor}/thread_pool/tests/queue.rs | 6 +- .../src/executor}/thread_pool/tests/worker.rs | 10 +- .../src/executor}/thread_pool/worker.rs | 18 +-- .../src => tokio/src/executor}/typed.rs | 6 +- .../src => tokio/src/executor}/util/mod.rs | 0 .../src => tokio/src/executor}/util/pad.rs | 0 .../src => tokio/src/executor}/util/rand.rs | 0 tokio/src/fs/mod.rs | 7 +- tokio/src/lib.rs | 8 +- tokio/src/net/addr.rs | 4 +- tokio/src/net/driver/mod.rs | 4 +- tokio/src/net/driver/reactor/mod.rs | 2 +- tokio/src/runtime/current_thread/builder.rs | 3 +- tokio/src/runtime/current_thread/mod.rs | 4 +- tokio/src/runtime/current_thread/runtime.rs | 11 +- tokio/src/runtime/mod.rs | 4 +- tokio/src/runtime/threadpool/builder.rs | 3 +- tokio/src/runtime/threadpool/mod.rs | 4 +- tokio/src/runtime/threadpool/spawner.rs | 3 +- tokio/src/timer/timer/mod.rs | 3 +- .../tests/current_thread.rs | 10 +- {tokio-executor => tokio}/tests/executor.rs | 4 +- .../enter.rs => tokio/tests/executor_enter.rs | 4 +- .../tests/executor_global.rs | 4 +- tokio/tests/net_driver.rs | 2 +- tokio/tests/runtime_current_thread.rs | 3 +- tokio/tests/runtime_threaded.rs | 5 +- .../tests/thread_pool.rs | 8 +- tokio/tests/timer_hammer.rs | 6 +- 101 files changed, 387 insertions(+), 690 deletions(-) delete mode 100644 tokio-executor/CHANGELOG.md delete mode 100644 tokio-executor/Cargo.toml delete mode 100644 tokio-executor/LICENSE delete mode 100644 tokio-executor/README.md delete mode 100644 tokio-executor/src/lib.rs rename {tokio-executor => tokio}/benches/thread_pool.rs (98%) delete mode 100644 tokio/src/executor.rs rename {tokio-executor/src => tokio/src/executor}/blocking/builder.rs (95%) rename {tokio-executor/src => tokio/src/executor}/blocking/mod.rs (98%) rename {tokio-executor/src => tokio/src/executor}/current_thread/mod.rs (97%) rename {tokio-executor/src => tokio/src/executor}/current_thread/scheduler.rs (99%) rename {tokio-executor/src => tokio/src/executor}/enter.rs (98%) rename {tokio-executor/src => tokio/src/executor}/error.rs (100%) rename {tokio-executor/src => tokio/src/executor}/executor.rs (97%) rename {tokio-executor/src => tokio/src/executor}/global.rs (81%) rename {tokio-executor/src => tokio/src/executor}/loom/mod.rs (85%) rename {tokio-executor/src => tokio/src/executor}/loom/std/atomic_u32.rs (100%) rename {tokio-executor/src => tokio/src/executor}/loom/std/atomic_usize.rs (97%) rename {tokio-executor/src => tokio/src/executor}/loom/std/causal_cell.rs (100%) rename {tokio-executor/src => tokio/src/executor}/loom/std/mod.rs (75%) create mode 100644 tokio/src/executor/mod.rs rename {tokio-executor/src => tokio/src/executor}/park/mod.rs (100%) rename {tokio-executor/src => tokio/src/executor}/park/thread.rs (97%) rename {tokio-executor/src => tokio/src/executor}/task/core.rs (94%) rename {tokio-executor/src => tokio/src/executor}/task/error.rs (100%) rename {tokio-executor/src => tokio/src/executor}/task/harness.rs (98%) rename {tokio-executor/src => tokio/src/executor}/task/join.rs (95%) rename {tokio-executor/src => tokio/src/executor}/task/list.rs (97%) rename {tokio-executor/src => tokio/src/executor}/task/mod.rs (100%) rename {tokio-executor/src => tokio/src/executor}/task/raw.rs (96%) rename {tokio-executor/src => tokio/src/executor}/task/stack.rs (96%) rename {tokio-executor/src => tokio/src/executor}/task/state.rs (98%) rename {tokio-executor/src => tokio/src/executor}/task/tests/loom.rs (98%) rename {tokio-executor/src => tokio/src/executor}/task/tests/mod.rs (100%) rename {tokio-executor/src => tokio/src/executor}/task/tests/task.rs (98%) rename {tokio-executor/src => tokio/src/executor}/task/waker.rs (96%) rename {tokio-executor/src => tokio/src/executor}/tests/backoff.rs (100%) rename {tokio-executor/src => tokio/src/executor}/tests/loom_oneshot.rs (100%) rename {tokio-executor/src => tokio/src/executor}/tests/loom_schedule.rs (96%) rename {tokio-executor/src => tokio/src/executor}/tests/mock_park.rs (96%) rename {tokio-executor/src => tokio/src/executor}/tests/mock_schedule.rs (98%) rename {tokio-executor/src => tokio/src/executor}/tests/mod.rs (100%) rename {tokio-executor/src => tokio/src/executor}/tests/track_drop.rs (100%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/builder.rs (89%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/current.rs (93%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/idle.rs (98%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/join.rs (89%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/mod.rs (96%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/owned.rs (94%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/park.rs (97%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/pool.rs (83%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/queue/global.rs (97%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/queue/inject.rs (87%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/queue/local.rs (97%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/queue/mod.rs (96%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/queue/worker.rs (96%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/set.rs (90%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/shared.rs (94%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/shutdown.rs (93%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/spawner.rs (88%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/tests/loom_pool.rs (90%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/tests/loom_queue.rs (91%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/tests/mod.rs (100%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/tests/queue.rs (97%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/tests/worker.rs (83%) rename {tokio-executor/src => tokio/src/executor}/thread_pool/worker.rs (95%) rename {tokio-executor/src => tokio/src/executor}/typed.rs (97%) rename {tokio-executor/src => tokio/src/executor}/util/mod.rs (100%) rename {tokio-executor/src => tokio/src/executor}/util/pad.rs (100%) rename {tokio-executor/src => tokio/src/executor}/util/rand.rs (100%) rename {tokio-executor => tokio}/tests/current_thread.rs (98%) rename {tokio-executor => tokio}/tests/executor.rs (84%) rename tokio-executor/tests/enter.rs => tokio/tests/executor_enter.rs (68%) rename tokio-executor/tests/global.rs => tokio/tests/executor_global.rs (74%) rename {tokio-executor => tokio}/tests/thread_pool.rs (98%) diff --git a/Cargo.toml b/Cargo.toml index d6703e16a..4a9e88a05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ members = [ "tokio", - "tokio-executor", "tokio-macros", "tokio-sync", "tokio-test", diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5b3188ea2..4fb217612 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -47,9 +47,6 @@ jobs: displayName: Test sub crates - rust: beta crates: - tokio-executor: - - current-thread - - thread-pool tokio-sync: - async-traits tokio-macros: [] @@ -58,22 +55,23 @@ jobs: examples: [] # Test compilation failure -- template: ci/azure-test-stable.yml - parameters: - name: test_features - displayName: Test feature flags - rust: beta - crates: - tests-build: - - tokio-executor - - executor-without-current-thread - # - macros-invalid-input - # - net-no-features - # - net-with-tcp - # - net-with-udp - # - net-with-uds - # - tokio-no-features - # - tokio-with-net +# Disable pending: https://github.com/tokio-rs/tokio/pull/1695#issuecomment-547045383 +# - template: ci/azure-test-stable.yml +# parameters: +# name: test_features +# displayName: Test feature flags +# rust: beta +# crates: +# tests-build: +# # - tokio-executor +# # - executor-without-current-thread +# # - macros-invalid-input +# # - net-no-features +# # - net-with-tcp +# # - net-with-udp +# # - net-with-uds +# # - tokio-no-features +# # - tokio-with-net # Run loom tests - template: ci/azure-loom.yml @@ -81,7 +79,6 @@ jobs: name: loom rust: beta crates: - - tokio-executor - tokio # Try cross compiling @@ -115,7 +112,7 @@ jobs: - clippy - test_tokio - test_linux - - test_features + # - test_features - loom # - test_nightly - cross diff --git a/ci/azure-tsan.yml b/ci/azure-tsan.yml index 3ce24ee84..0104697e1 100644 --- a/ci/azure-tsan.yml +++ b/ci/azure-tsan.yml @@ -5,8 +5,6 @@ jobs: matrix: Timer: cmd: cargo test -p tokio-timer --test hammer - Threadpool: - cmd: cargo test -p tokio-executor --tests --features threadpool pool: vmImage: ubuntu-16.04 steps: diff --git a/ci/patch.toml b/ci/patch.toml index 6718f231f..333c4dfff 100644 --- a/ci/patch.toml +++ b/ci/patch.toml @@ -2,7 +2,6 @@ # repository. [patch.crates-io] tokio = { path = "tokio" } -tokio-executor = { path = "tokio-executor" } tokio-macros = { path = "tokio-macros" } tokio-sync = { path = "tokio-sync" } tokio-tls = { path = "tokio-tls" } diff --git a/tests-build/Cargo.toml b/tests-build/Cargo.toml index fb837d03f..36dbc883c 100644 --- a/tests-build/Cargo.toml +++ b/tests-build/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" publish = false [features] -executor-without-current-thread = ["tokio-executor"] +# executor-without-current-thread = ["tokio-executor"] # macros-invalid-input = ["tokio/rt-full"] # net-no-features = ["tokio-net"] # net-with-tcp = ["tokio-net/tcp"] @@ -19,7 +19,6 @@ executor-without-current-thread = ["tokio-executor"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tokio-executor = { path = "../tokio-executor", optional = true } # tokio = { path = "../tokio", optional = true, default-features = false } [dev-dependencies] diff --git a/tokio-executor/CHANGELOG.md b/tokio-executor/CHANGELOG.md deleted file mode 100644 index d2cca0ba7..000000000 --- a/tokio-executor/CHANGELOG.md +++ /dev/null @@ -1,81 +0,0 @@ -# 0.2.0-alpha.6 (September 30, 2019) - -- Move to `futures-*-preview 0.3.0-alpha.19` -- Move to `pin-project 0.4` - -# 0.2.0-alpha.5 (September 19, 2019) - -### Fix -- shutdown blocking pool threads when idle (#1562, #1514). - -# 0.2.0-alpha.4 (August 29, 2019) - -- Track tokio release. - -# 0.2.0-alpha.3 (August 28, 2019) - -### Changed -- use `tracing` instead of `log` - -### Added -- thread pool dedicated to blocking operations (#1495). -- `Executor::spawn_with_handle` (#1492). - -# 0.2.0-alpha.2 (August 17, 2019) - -### Fixed -- allow running executor from within blocking clause (#1433). - -### Changed -- Update `futures` dependency to 0.3.0-alpha.18. - -### Added -- Import `current-thread` executor (#1447). -- Import `threadpool` executor (#1152). - -# 0.2.0-alpha.1 (August 8, 2019) - -### Changed -- Switch to `async`, `await`, and `std::future`. - -### Removed -- `Enter::make_permanent` and `Enter::on_exit` (#???) - -# 0.1.7 (March 22, 2019) - -### Added -- `TypedExecutor` for spawning futures of a specific type (#993). - -# 0.1.6 (January 6, 2019) - -* Implement `Unpark` for `Arc` (#802). -* Switch to crossbeam's Parker / Unparker (#528). - -# 0.1.5 (September 26, 2018) - -* Implement `futures::Executor` for `DefaultExecutor` (#563). -* Add `Enter::block_on(future)` (#646) - -# 0.1.4 (August 23, 2018) - -* Implement `std::error::Error` for error types (#511). - -# 0.1.3 (August 6, 2018) - -* Implement `Executor` for `Box` (#420). -* Improve `EnterError` debug message (#410). -* Implement `status`, `Send`, and `Sync` for `DefaultExecutor` (#463, #472). -* Fix race in `ParkThread` (#507). -* Handle recursive calls into `DefaultExecutor` (#473). - -# 0.1.2 (March 30, 2018) - -* Implement `Unpark` for `Box`. - -# 0.1.1 (March 22, 2018) - -* Optionally support futures 0.2. - -# 0.1.0 (March 09, 2018) - -* Initial release diff --git a/tokio-executor/Cargo.toml b/tokio-executor/Cargo.toml deleted file mode 100644 index d1bd6a189..000000000 --- a/tokio-executor/Cargo.toml +++ /dev/null @@ -1,52 +0,0 @@ -[package] -name = "tokio-executor" -# When releasing to crates.io: -# - Remove path dependencies -# - Update html_root_url. -# - Update doc url -# - Cargo.toml -# - Update CHANGELOG.md. -# - Create "v0.2.x" git tag. -version = "0.2.0-alpha.6" -edition = "2018" -documentation = "https://docs.rs/tokio-executor/0.2.0-alpha.6/tokio_executor" -repository = "https://github.com/tokio-rs/tokio" -homepage = "https://github.com/tokio-rs/tokio" -license = "MIT" -authors = ["Tokio Contributors "] -description = """ -Future execution primitives -""" -keywords = ["futures", "tokio"] -categories = ["concurrency", "asynchronous"] - -[features] -blocking = ["lazy_static"] -current-thread = ["crossbeam-channel"] -thread-pool = ["num_cpus"] - -[dependencies] -futures-util-preview = { version = "=0.3.0-alpha.19", features = ["channel"] } -tokio-sync = { version = "=0.2.0-alpha.6", path = "../tokio-sync" } - -# current-thread dependencies -crossbeam-channel = { version = "0.3.8", optional = true } - -# threadpool dependencies -num_cpus = { version = "1.2", optional = true } - -# blocking -futures-core-preview = { version = "=0.3.0-alpha.19", optional = true } -lazy_static = { version = "1", optional = true } - -[dev-dependencies] -tokio = { version = "=0.2.0-alpha.6", path = "../tokio" } -tokio-sync = { version = "=0.2.0-alpha.6", path = "../tokio-sync" } -tokio-test = { version = "=0.2.0-alpha.6", path = "../tokio-test" } - -futures-core-preview = "=0.3.0-alpha.19" -loom = { version = "0.2.11", features = ["futures", "checkpoint"] } -rand = "0.7" - -[package.metadata.docs.rs] -all-features = true diff --git a/tokio-executor/LICENSE b/tokio-executor/LICENSE deleted file mode 100644 index cdb28b4b5..000000000 --- a/tokio-executor/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2019 Tokio Contributors - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/tokio-executor/README.md b/tokio-executor/README.md deleted file mode 100644 index 328b52b6d..000000000 --- a/tokio-executor/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# tokio-executor - -Task execution related traits and utilities. - -## License - -This project is licensed under the [MIT license](LICENSE). - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in Tokio by you, shall be licensed as MIT, without any additional -terms or conditions. diff --git a/tokio-executor/src/lib.rs b/tokio-executor/src/lib.rs deleted file mode 100644 index d1f0f52dc..000000000 --- a/tokio-executor/src/lib.rs +++ /dev/null @@ -1,102 +0,0 @@ -#![doc(html_root_url = "https://docs.rs/tokio-executor/0.2.0-alpha.6")] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] -#![deny(intra_doc_link_resolution_failure)] -#![doc(test( - no_crate_inject, - attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) -))] - -//! Task execution related traits and utilities. -//! -//! In the Tokio execution model, futures are lazy. When a future is created, no -//! work is performed. In order for the work defined by the future to happen, -//! the future must be submitted to an executor. A future that is submitted to -//! an executor is called a "task". -//! -//! The executor is responsible for ensuring that [`Future::poll`] is called -//! whenever the task is notified. Notification happens when the internal -//! state of a task transitions from *not ready* to *ready*. For example, a -//! socket might have received data and a call to `read` will now be able to -//! succeed. -//! -//! This crate provides traits and utilities that are necessary for building an -//! executor, including: -//! -//! * The [`Executor`] trait spawns future object onto an executor. -//! -//! * The [`TypedExecutor`] trait spawns futures of a specific type onto an -//! executor. This is used to be generic over executors that spawn futures -//! that are either `Send` or `!Send` or implement executors that apply to -//! specific futures. -//! -//! * [`enter`] marks that the current thread is entering an execution -//! context. This prevents a second executor from accidentally starting from -//! within the context of one that is already running. -//! -//! * [`DefaultExecutor`] spawns tasks onto the default executor for the current -//! context. -//! -//! * [`Park`] abstracts over blocking and unblocking the current thread. -//! -//! # Implementing an executor -//! -//! Executors should always implement `TypedExecutor`. This usually is the bound -//! that applications and libraries will use when generic over an executor. See -//! the [trait documentation][`TypedExecutor`] for more details. -//! -//! If the executor is able to spawn all futures that are `Send`, then the -//! executor should also implement the `Executor` trait. This trait is rarely -//! used directly by applications and libraries. Instead, `tokio::spawn` is -//! configured to dispatch to type that implements `Executor`. -//! -//! [`Executor`]: trait.Executor.html -//! [`TypedExecutor`]: trait.TypedExecutor.html -//! [`enter`]: fn.enter.html -//! [`DefaultExecutor`]: struct.DefaultExecutor.html -//! [`Park`]: park/index.html -//! [`Future::poll`]: https://doc.rust-lang.org/std/future/trait.Future.html#tymethod.poll - -#[cfg(all(test, loom))] -macro_rules! thread_local { - ($($tts:tt)+) => { loom::thread_local!{ $($tts)+ } } -} - -// At the top due to macros -#[cfg(test)] -#[macro_use] -mod tests; - -mod enter; -mod error; -mod executor; -mod global; -mod loom; -pub mod park; -#[cfg(feature = "thread-pool")] -mod task; -mod typed; -#[cfg(feature = "thread-pool")] -mod util; - -#[cfg(all(not(feature = "blocking"), feature = "thread-pool"))] -mod blocking; -#[cfg(feature = "blocking")] -pub mod blocking; - -#[cfg(feature = "current-thread")] -pub mod current_thread; - -#[cfg(feature = "thread-pool")] -pub mod thread_pool; - -pub use crate::enter::{enter, exit, Enter, EnterError}; -pub use crate::error::SpawnError; -pub use crate::executor::Executor; -pub use crate::global::{spawn, with_default, DefaultExecutor}; -pub use crate::typed::TypedExecutor; -pub use futures_util::future::RemoteHandle; diff --git a/tokio-test/Cargo.toml b/tokio-test/Cargo.toml index b53f9f0bd..d5f637230 100644 --- a/tokio-test/Cargo.toml +++ b/tokio-test/Cargo.toml @@ -21,7 +21,6 @@ categories = ["asynchronous", "testing"] [dependencies] tokio = { version = "=0.2.0-alpha.6", path = "../tokio" } -tokio-executor = { version = "=0.2.0-alpha.6", path = "../tokio-executor" } tokio-sync = { version = "=0.2.0-alpha.6", path = "../tokio-sync" } bytes = "0.4" diff --git a/tokio-test/src/clock.rs b/tokio-test/src/clock.rs index dd09a0095..c5fac787f 100644 --- a/tokio-test/src/clock.rs +++ b/tokio-test/src/clock.rs @@ -22,9 +22,9 @@ //! }); //! ``` +use tokio::executor::park::{Park, Unpark}; use tokio::timer::clock::{Clock, Now}; use tokio::timer::Timer; -use tokio_executor::park::{Park, Unpark}; use std::marker::PhantomData; use std::rc::Rc; diff --git a/tokio-test/src/task.rs b/tokio-test/src/task.rs index 91da41eb5..5468749a6 100644 --- a/tokio-test/src/task.rs +++ b/tokio-test/src/task.rs @@ -1,6 +1,6 @@ //! Futures task based helpers -use tokio_executor::enter; +use tokio::executor::enter; use pin_convert::AsPinMut; use std::future::Future; diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index aa60ae222..569a3fe71 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -25,6 +25,7 @@ keywords = ["io", "async", "non-blocking", "futures"] [features] default = [ + "blocking", "fs", "io", "net-full", @@ -35,25 +36,25 @@ default = [ "timer", ] -fs = ["tokio-executor/blocking"] +blocking = [] +fs = ["blocking"] io-traits = ["bytes", "iovec"] io-util = ["io-traits", "pin-project", "memchr"] io = ["io-traits", "io-util"] macros = ["tokio-macros"] net-full = ["tcp", "udp", "uds"] -net-driver = ["mio", "tokio-executor/blocking", "lazy_static"] +net-driver = ["mio", "blocking", "lazy_static"] rt-current-thread = [ + "crossbeam-channel", "timer", - "tokio-executor/current-thread", ] rt-full = [ "macros", "num_cpus", "net-full", + "rt-current-thread", "sync", "timer", - "tokio-executor/current-thread", - "tokio-executor/thread-pool", ] signal = [ "lazy_static", @@ -82,10 +83,11 @@ process = [ [dependencies] futures-core-preview = "=0.3.0-alpha.19" futures-sink-preview = "=0.3.0-alpha.19" -futures-util-preview = { version = "=0.3.0-alpha.19", features = ["sink"] } +futures-util-preview = { version = "=0.3.0-alpha.19", features = ["sink", "channel"] } # Everything else is optional... bytes = { version = "0.4", optional = true } +crossbeam-channel = { version = "0.3.8", optional = true } crossbeam-utils = { version = "0.6.0", optional = true } iovec = { version = "0.1", optional = true } lazy_static = { version = "1.0.2", optional = true } @@ -95,7 +97,6 @@ num_cpus = { version = "1.8.0", optional = true } pin-project = { version = "0.4", optional = true } # Backs `DelayQueue` slab = { version = "0.4.1", optional = true } -tokio-executor = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-executor" } tokio-macros = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-macros" } tokio-sync = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-sync", features = ["async-traits"] } @@ -113,10 +114,6 @@ version = "0.3.8" default-features = false optional = true -[target.'cfg(loom)'.dependencies] -# play nice with loom tests in other crates. -loom = "0.2.11" - [dev-dependencies] tokio-test = { version = "=0.2.0-alpha.6", path = "../tokio-test" } tokio-util = { version = "=0.2.0-alpha.6", path = "../tokio-util" } @@ -127,6 +124,7 @@ flate2 = { version = "1", features = ["tokio"] } http = "0.1" httparse = "1.0" libc = "0.2" +loom = { version = "0.2.11", features = ["futures", "checkpoint"] } num_cpus = "1.0" rand = "0.7.2" serde = { version = "1.0", features = ["derive"] } @@ -135,7 +133,6 @@ tempfile = "3.1.0" time = "0.1" # sharded slab tests -loom = "0.2.11" proptest = "0.9.4" [package.metadata.docs.rs] diff --git a/tokio-executor/benches/thread_pool.rs b/tokio/benches/thread_pool.rs similarity index 98% rename from tokio-executor/benches/thread_pool.rs rename to tokio/benches/thread_pool.rs index 003c7ca97..3e1462f3f 100644 --- a/tokio-executor/benches/thread_pool.rs +++ b/tokio/benches/thread_pool.rs @@ -2,7 +2,7 @@ extern crate test; -use tokio_executor::thread_pool::{Builder, Spawner, ThreadPool}; +use tokio::executor::thread_pool::{Builder, Spawner}; use tokio_sync::oneshot; use std::future::Future; diff --git a/tokio/src/executor.rs b/tokio/src/executor.rs deleted file mode 100644 index 710ed2b95..000000000 --- a/tokio/src/executor.rs +++ /dev/null @@ -1,104 +0,0 @@ -//! Task execution utilities. -//! -//! In the Tokio execution model, futures are lazy. When a future is created, no -//! work is performed. In order for the work defined by the future to happen, -//! the future must be submitted to an executor. A future that is submitted to -//! an executor is called a "task". -//! -//! The executor is responsible for ensuring that [`Future::poll`] is -//! called whenever the task is [notified]. Notification happens when the -//! internal state of a task transitions from "not ready" to ready. For -//! example, a socket might have received data and a call to `read` will now be -//! able to succeed. -//! -//! The specific strategy used to manage the tasks is left up to the -//! executor. There are two main flavors of executors: single-threaded and -//! multi-threaded. Tokio provides implementation for both of these in the -//! [`runtime`] module. -//! -//! # `Executor` trait. -//! -//! This module provides the [`Executor`] trait (re-exported from -//! [`tokio-executor`]), which describes the API that all executors must -//! implement. -//! -//! A free [`spawn`] function is provided that allows spawning futures onto the -//! default executor (tracked via a thread-local variable) without referencing a -//! handle. It is expected that all executors will set a value for the default -//! executor. This value will often be set to the executor itself, but it is -//! possible that the default executor might be set to a different executor. -//! -//! For example, a single threaded executor might set the default executor to a -//! thread pool instead of itself, allowing futures to spawn new tasks onto the -//! thread pool when those tasks are `Send`. -//! -//! [`Future::poll`]: https://docs.rs/futures/0.1/futures/future/trait.Future.html#tymethod.poll -//! [notified]: https://docs.rs/futures/0.1/futures/executor/trait.Notify.html#tymethod.notify -//! [`runtime`]: ../runtime/index.html -//! [`tokio-executor`]: https://docs.rs/tokio-executor/0.1 -//! [`Executor`]: trait.Executor.html -//! [`spawn`]: fn.spawn.html - -use std::future::Future; -pub use tokio_executor::{DefaultExecutor, Executor, SpawnError, TypedExecutor}; - -/// Return value from the `spawn` function. -/// -/// Currently this value doesn't actually provide any functionality. However, it -/// provides a way to add functionality later without breaking backwards -/// compatibility. -/// -/// See [`spawn`] for more details. -/// -/// [`spawn`]: fn.spawn.html -#[derive(Debug)] -pub struct Spawn(()); - -/// Spawns a future on the default executor. -/// -/// In order for a future to do work, it must be spawned on an executor. The -/// `spawn` function is the easiest way to do this. It spawns a future on the -/// [default executor] for the current execution context (tracked using a -/// thread-local variable). -/// -/// The default executor is **usually** a thread pool. -/// -/// # Examples -/// -/// In this example, a server is started and `spawn` is used to start a new task -/// that processes each received connection. -/// -/// ``` -/// use tokio::net::TcpListener; -/// -/// # async fn process(_t: T) {} -/// # async fn dox() -> Result<(), Box> { -/// let mut listener = TcpListener::bind("127.0.0.1:8080").await?; -/// -/// loop { -/// let (socket, _) = listener.accept().await?; -/// -/// tokio::spawn(async move { -/// // Process each socket concurrently. -/// process(socket).await -/// }); -/// } -/// # } -/// ``` -/// -/// [default executor]: struct.DefaultExecutor.html -/// -/// # Panics -/// -/// This function will panic if the default executor is not set or if spawning -/// onto the default executor returns an error. To avoid the panic, use -/// [`DefaultExecutor`]. -/// -/// [`DefaultExecutor`]: struct.DefaultExecutor.html -pub fn spawn(f: F) -> Spawn -where - F: Future + 'static + Send, -{ - ::tokio_executor::spawn(f); - Spawn(()) -} diff --git a/tokio-executor/src/blocking/builder.rs b/tokio/src/executor/blocking/builder.rs similarity index 95% rename from tokio-executor/src/blocking/builder.rs rename to tokio/src/executor/blocking/builder.rs index 3cf1aef8f..05ea28c2b 100644 --- a/tokio-executor/src/blocking/builder.rs +++ b/tokio/src/executor/blocking/builder.rs @@ -1,5 +1,6 @@ -use super::Pool; -use crate::loom::thread; +use crate::executor::blocking::Pool; +use crate::executor::loom::thread; + use std::usize; /// Builds a blocking thread pool with custom configuration values. diff --git a/tokio-executor/src/blocking/mod.rs b/tokio/src/executor/blocking/mod.rs similarity index 98% rename from tokio-executor/src/blocking/mod.rs rename to tokio/src/executor/blocking/mod.rs index 34c521815..16faa03e4 100644 --- a/tokio-executor/src/blocking/mod.rs +++ b/tokio/src/executor/blocking/mod.rs @@ -1,7 +1,7 @@ //! Thread pool for blocking operations -use crate::loom::sync::{Arc, Condvar, Mutex}; -use crate::loom::thread; +use crate::executor::loom::sync::{Arc, Condvar, Mutex}; +use crate::executor::loom::thread; #[cfg(feature = "blocking")] use tokio_sync::oneshot; @@ -17,10 +17,10 @@ use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] mod builder; -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] pub(crate) use builder::Builder; #[derive(Clone, Copy)] @@ -259,7 +259,7 @@ impl Drop for PoolWaiter { /// /// ``` /// # async fn docs() { -/// tokio_executor::blocking::run(move || { +/// tokio::executor::blocking::run(move || { /// // do some compute-heavy work or call synchronous code /// }).await; /// # } diff --git a/tokio-executor/src/current_thread/mod.rs b/tokio/src/executor/current_thread/mod.rs similarity index 97% rename from tokio-executor/src/current_thread/mod.rs rename to tokio/src/executor/current_thread/mod.rs index f302b0192..dcc9c51ac 100644 --- a/tokio-executor/src/current_thread/mod.rs +++ b/tokio/src/executor/current_thread/mod.rs @@ -16,12 +16,12 @@ //! [`block_on_all`]: fn.block_on_all.html mod scheduler; - use self::scheduler::{Scheduler, TickArgs}; + +use crate::executor::{EnterError, Executor, SpawnError, TypedExecutor}; #[cfg(feature = "blocking")] -use crate::blocking::{Pool, PoolWaiter}; -use crate::park::{Park, ParkThread, Unpark}; -use crate::{EnterError, Executor, SpawnError, TypedExecutor}; +use crate::executor::blocking::{Pool, PoolWaiter}; +use crate::executor::park::{Park, ParkThread, Unpark}; use std::cell::Cell; use std::error::Error; @@ -326,21 +326,21 @@ impl CurrentThread

{ where F: Future, { - let _enter = crate::enter().expect("failed to start `current_thread::Runtime`"); + let _enter = crate::executor::enter().expect("failed to start `current_thread::Runtime`"); self.enter().block_on(future) } /// Run the executor to completion, blocking the thread until **all** /// spawned futures have completed. pub fn run(&mut self) -> Result<(), RunError> { - let _enter = crate::enter().expect("failed to start `current_thread::Runtime`"); + let _enter = crate::executor::enter().expect("failed to start `current_thread::Runtime`"); self.enter().run() } /// Run the executor to completion, blocking the thread until all /// spawned futures have completed **or** `duration` time has elapsed. pub fn run_timeout(&mut self, duration: Duration) -> Result<(), RunTimeoutError> { - let _enter = crate::enter().expect("failed to start `current_thread::Runtime`"); + let _enter = crate::executor::enter().expect("failed to start `current_thread::Runtime`"); self.enter().run_timeout(duration) } @@ -348,7 +348,7 @@ impl CurrentThread

{ /// /// This function blocks the current thread even if the executor is idle. pub fn turn(&mut self, duration: Option) -> Result { - let _enter = crate::enter().expect("failed to start `current_thread::Runtime`"); + let _enter = crate::executor::enter().expect("failed to start `current_thread::Runtime`"); self.enter().turn(duration) } @@ -786,7 +786,7 @@ impl Borrow<'_, U> { current.set_spawn(spawner, || { #[cfg(all(feature = "blocking", not(loom)))] - let res = crate::blocking::with_pool(blocking, || f()); + let res = crate::executor::blocking::with_pool(blocking, || f()); #[cfg(any(not(feature = "blocking"), loom))] let res = f(); res diff --git a/tokio-executor/src/current_thread/scheduler.rs b/tokio/src/executor/current_thread/scheduler.rs similarity index 99% rename from tokio-executor/src/current_thread/scheduler.rs rename to tokio/src/executor/current_thread/scheduler.rs index 0793a0670..ba14ee881 100644 --- a/tokio-executor/src/current_thread/scheduler.rs +++ b/tokio/src/executor/current_thread/scheduler.rs @@ -1,5 +1,5 @@ -use super::{Borrow, BorrowSpawner}; -use crate::park::Unpark; +use crate::executor::current_thread::{Borrow, BorrowSpawner}; +use crate::executor::park::Unpark; use std::cell::UnsafeCell; use std::fmt::{self, Debug}; @@ -128,7 +128,7 @@ pub(super) struct TickArgs<'a> { pub(super) id: u64, pub(super) num_futures: &'a AtomicUsize, #[cfg(feature = "blocking")] - pub(super) blocking: &'a crate::blocking::PoolWaiter, + pub(super) blocking: &'a crate::executor::blocking::PoolWaiter, } impl Scheduler diff --git a/tokio-executor/src/enter.rs b/tokio/src/executor/enter.rs similarity index 98% rename from tokio-executor/src/enter.rs rename to tokio/src/executor/enter.rs index 37a09bfb8..56b645a76 100644 --- a/tokio-executor/src/enter.rs +++ b/tokio/src/executor/enter.rs @@ -101,7 +101,7 @@ impl Enter { /// Blocks the thread on the specified future, returning the value with /// which that future completes. pub fn block_on(&mut self, mut f: F) -> F::Output { - use crate::park::{Park, ParkThread}; + use crate::executor::park::{Park, ParkThread}; use std::pin::Pin; use std::task::Context; use std::task::Poll::Ready; diff --git a/tokio-executor/src/error.rs b/tokio/src/executor/error.rs similarity index 100% rename from tokio-executor/src/error.rs rename to tokio/src/executor/error.rs diff --git a/tokio-executor/src/executor.rs b/tokio/src/executor/executor.rs similarity index 97% rename from tokio-executor/src/executor.rs rename to tokio/src/executor/executor.rs index 964a4099c..5eeb43a22 100644 --- a/tokio-executor/src/executor.rs +++ b/tokio/src/executor/executor.rs @@ -1,4 +1,5 @@ -use crate::SpawnError; +use crate::executor::SpawnError; + use futures_util::future::{FutureExt, RemoteHandle}; use std::future::Future; use std::pin::Pin; @@ -50,7 +51,7 @@ use std::pin::Pin; /// # Examples /// /// ``` -/// use tokio_executor::Executor; +/// use tokio::executor::Executor; /// /// # fn docs(my_executor: &mut dyn Executor) { /// my_executor.spawn(Box::pin(async { @@ -78,7 +79,7 @@ pub trait Executor { /// # Examples /// /// ``` - /// use tokio_executor::Executor; + /// use tokio::executor::Executor; /// /// # fn docs(my_executor: &mut dyn Executor) { /// my_executor.spawn(Box::pin(async { @@ -107,7 +108,7 @@ pub trait Executor { /// # Examples /// /// ``` - /// use tokio_executor::Executor; + /// use tokio::executor::Executor; /// /// # fn docs(my_executor: &mut dyn Executor) { /// if my_executor.status().is_ok() { @@ -141,7 +142,7 @@ impl dyn Executor { /// # Examples /// /// ``` - /// use tokio_executor::Executor; + /// use tokio::executor::Executor; /// use futures_util::future::FutureExt; /// /// # fn docs(my_executor: &'static mut (dyn Executor + 'static)) { diff --git a/tokio-executor/src/global.rs b/tokio/src/executor/global.rs similarity index 81% rename from tokio-executor/src/global.rs rename to tokio/src/executor/global.rs index 11ede54bb..c60d4511d 100644 --- a/tokio-executor/src/global.rs +++ b/tokio/src/executor/global.rs @@ -1,6 +1,6 @@ -#[cfg(feature = "thread-pool")] -use crate::thread_pool::ThreadPool; -use crate::{Executor, SpawnError}; +#[cfg(feature = "rt-full")] +use crate::executor::thread_pool::ThreadPool; +use crate::executor::{Executor, SpawnError}; use std::cell::Cell; use std::future::Future; @@ -15,7 +15,7 @@ use std::pin::Pin; /// executor (usually itself) that is used to spawn new tasks. /// /// The current `DefaultExecutor` reference is tracked using a thread-local -/// variable and is set using `tokio_executor::with_default` +/// variable and is set using `tokio::executor::with_default` #[derive(Debug, Clone)] pub struct DefaultExecutor { _dummy: (), @@ -45,7 +45,7 @@ impl DefaultExecutor { let executor = unsafe { &mut *executor_ptr }; Some(f(executor)) } - #[cfg(feature = "thread-pool")] + #[cfg(feature = "rt-full")] State::ThreadPool(threadpool_ptr) => { let mut thread_pool = unsafe { &*threadpool_ptr }; Some(f(&mut thread_pool)) @@ -61,7 +61,7 @@ enum State { Empty, // default executor is a thread pool instance. - #[cfg(feature = "thread-pool")] + #[cfg(feature = "rt-full")] ThreadPool(*const ThreadPool), // default executor is set to a custom executor. @@ -105,36 +105,47 @@ where // ===== global spawn fns ===== -/// Submits a future for execution on the default executor -- usually a -/// threadpool. +/// Spawns a future on the default executor. /// -/// Futures are lazy constructs. When they are defined, no work happens. In -/// order for the logic defined by the future to be run, the future must be -/// spawned on an executor. This function is the easiest way to do so. +/// In order for a future to do work, it must be spawned on an executor. The +/// `spawn` function is the easiest way to do this. It spawns a future on the +/// [default executor] for the current execution context (tracked using a +/// thread-local variable). /// -/// This function must be called from an execution context, i.e. from a future -/// that has been already spawned onto an executor. +/// The default executor is **usually** a thread pool. /// -/// Once spawned, the future will execute. The details of how that happens is -/// left up to the executor instance. If the executor is a thread pool, the -/// future will be pushed onto a queue that a worker thread polls from. If the -/// executor is a "current thread" executor, the future might be polled -/// immediately from within the call to `spawn` or it might be pushed onto an -/// internal queue. +/// # Examples +/// +/// In this example, a server is started and `spawn` is used to start a new task +/// that processes each received connection. +/// +/// ``` +/// use tokio::net::TcpListener; +/// +/// # async fn process(_t: T) {} +/// # async fn dox() -> Result<(), Box> { +/// let mut listener = TcpListener::bind("127.0.0.1:8080").await?; +/// +/// loop { +/// let (socket, _) = listener.accept().await?; +/// +/// tokio::spawn(async move { +/// // Process each socket concurrently. +/// process(socket).await +/// }); +/// } +/// # } +/// ``` +/// +/// [default executor]: struct.DefaultExecutor.html /// /// # Panics /// /// This function will panic if the default executor is not set or if spawning -/// onto the default executor returns an error. To avoid the panic, use the -/// `DefaultExecutor` handle directly. +/// onto the default executor returns an error. To avoid the panic, use +/// [`DefaultExecutor`]. /// -/// # Examples -/// -/// ```no_run -/// tokio::spawn(async { -/// println!("running on the default executor"); -/// }); -/// ``` +/// [`DefaultExecutor`]: struct.DefaultExecutor.html pub fn spawn(future: T) where T: Future + Send + 'static, @@ -144,7 +155,7 @@ where let executor = unsafe { &mut *executor_ptr }; executor.spawn(Box::pin(future)).unwrap(); } - #[cfg(feature = "thread-pool")] + #[cfg(feature = "rt-full")] State::ThreadPool(threadpool_ptr) => { let thread_pool = unsafe { &*threadpool_ptr }; thread_pool.spawn_background(future); @@ -153,7 +164,7 @@ where }) } -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] pub(crate) fn with_threadpool(thread_pool: &ThreadPool, f: F) -> R where F: FnOnce() -> R, diff --git a/tokio-executor/src/loom/mod.rs b/tokio/src/executor/loom/mod.rs similarity index 85% rename from tokio-executor/src/loom/mod.rs rename to tokio/src/executor/loom/mod.rs index bbfac05cb..97eeb7e32 100644 --- a/tokio-executor/src/loom/mod.rs +++ b/tokio/src/executor/loom/mod.rs @@ -21,7 +21,7 @@ pub(crate) mod std { } pub(crate) use self::std::sync; -#[cfg(any(feature = "blocking", feature = "thread-pool"))] +#[cfg(any(feature = "blocking", feature = "rt-full"))] pub(crate) use self::std::thread; -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] pub(crate) use self::std::{alloc, cell, rand, sys}; diff --git a/tokio-executor/src/loom/std/atomic_u32.rs b/tokio/src/executor/loom/std/atomic_u32.rs similarity index 100% rename from tokio-executor/src/loom/std/atomic_u32.rs rename to tokio/src/executor/loom/std/atomic_u32.rs diff --git a/tokio-executor/src/loom/std/atomic_usize.rs b/tokio/src/executor/loom/std/atomic_usize.rs similarity index 97% rename from tokio-executor/src/loom/std/atomic_usize.rs rename to tokio/src/executor/loom/std/atomic_usize.rs index e9db9a41d..3cabbded2 100644 --- a/tokio-executor/src/loom/std/atomic_usize.rs +++ b/tokio/src/executor/loom/std/atomic_usize.rs @@ -22,7 +22,7 @@ impl AtomicUsize { /// /// All mutations must have happened before the unsynchronized load. /// Additionally, there must be no concurrent mutations. - #[cfg(feature = "thread-pool")] + #[cfg(feature = "rt-full")] pub(crate) unsafe fn unsync_load(&self) -> usize { *(*self.inner.get()).get_mut() } diff --git a/tokio-executor/src/loom/std/causal_cell.rs b/tokio/src/executor/loom/std/causal_cell.rs similarity index 100% rename from tokio-executor/src/loom/std/causal_cell.rs rename to tokio/src/executor/loom/std/causal_cell.rs diff --git a/tokio-executor/src/loom/std/mod.rs b/tokio/src/executor/loom/std/mod.rs similarity index 75% rename from tokio-executor/src/loom/std/mod.rs rename to tokio/src/executor/loom/std/mod.rs index c051bdacf..568912bf4 100644 --- a/tokio-executor/src/loom/std/mod.rs +++ b/tokio/src/executor/loom/std/mod.rs @@ -1,10 +1,10 @@ -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] mod atomic_u32; mod atomic_usize; -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] mod causal_cell; -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] pub(crate) mod alloc { #[derive(Debug)] pub(crate) struct Track { @@ -26,12 +26,12 @@ pub(crate) mod alloc { } } -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] pub(crate) mod cell { pub(crate) use super::causal_cell::{CausalCell, CausalCheck}; } -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] pub(crate) mod rand { use std::collections::hash_map::RandomState; use std::hash::{BuildHasher, Hash, Hasher}; @@ -57,21 +57,21 @@ pub(crate) mod sync { pub(crate) use std::sync::{Arc, Condvar, Mutex}; pub(crate) mod atomic { - #[cfg(feature = "thread-pool")] - pub(crate) use crate::loom::std::atomic_u32::AtomicU32; - pub(crate) use crate::loom::std::atomic_usize::AtomicUsize; + #[cfg(feature = "rt-full")] + pub(crate) use crate::executor::loom::std::atomic_u32::AtomicU32; + pub(crate) use crate::executor::loom::std::atomic_usize::AtomicUsize; - #[cfg(feature = "thread-pool")] + #[cfg(feature = "rt-full")] pub(crate) use std::sync::atomic::{fence, spin_loop_hint, AtomicPtr}; } } -#[cfg(feature = "thread-pool")] +#[cfg(feature = "rt-full")] pub(crate) mod sys { pub(crate) fn num_cpus() -> usize { usize::max(1, num_cpus::get_physical()) } } -#[cfg(any(feature = "blocking", feature = "thread-pool"))] +#[cfg(any(feature = "blocking", feature = "rt-full"))] pub(crate) use std::thread; diff --git a/tokio/src/executor/mod.rs b/tokio/src/executor/mod.rs new file mode 100644 index 000000000..9044cfc7b --- /dev/null +++ b/tokio/src/executor/mod.rs @@ -0,0 +1,84 @@ +//! Task execution related traits and utilities. +//! +//! In the Tokio execution model, futures are lazy. When a future is created, no +//! work is performed. In order for the work defined by the future to happen, +//! the future must be submitted to an executor. A future that is submitted to +//! an executor is called a "task". +//! +//! The executor is responsible for ensuring that [`Future::poll`] is called +//! whenever the task is notified. Notification happens when the internal +//! state of a task transitions from *not ready* to *ready*. For example, a +//! socket might have received data and a call to `read` will now be able to +//! succeed. +//! +//! The specific strategy used to manage the tasks is left up to the +//! executor. There are two main flavors of executors: single-threaded and +//! multi-threaded. Tokio provides implementation for both of these in the +//! [`runtime`] module. +//! +//! # `Executor` trait. +//! +//! This module provides the [`Executor`] trait (re-exported from +//! [`tokio-executor`]), which describes the API that all executors must +//! implement. +//! +//! A free [`spawn`] function is provided that allows spawning futures onto the +//! default executor (tracked via a thread-local variable) without referencing a +//! handle. It is expected that all executors will set a value for the default +//! executor. This value will often be set to the executor itself, but it is +//! possible that the default executor might be set to a different executor. +//! +//! For example, a single threaded executor might set the default executor to a +//! thread pool instead of itself, allowing futures to spawn new tasks onto the +//! thread pool when those tasks are `Send`. +//! +//! [`Future::poll`]: https://docs.rs/futures/0.1/futures/future/trait.Future.html#tymethod.poll +//! [notified]: https://docs.rs/futures/0.1/futures/executor/trait.Notify.html#tymethod.notify +//! [`runtime`]: ../runtime/index.html +//! [`tokio-executor`]: https://docs.rs/tokio-executor/0.1 +//! [`Executor`]: trait.Executor.html +//! [`spawn`]: fn.spawn.html#[cfg(all(test, loom))] + +// At the top due to macros +#[cfg(test)] +#[macro_use] +mod tests; + +mod enter; +pub use self::enter::{enter, exit, Enter, EnterError}; + +mod error; +pub use self::error::SpawnError; + +#[allow(clippy::module_inception)] +mod executor; +pub use self::executor::Executor; + +mod global; +pub use self::global::{spawn, with_default, DefaultExecutor}; + +mod loom; + +pub mod park; + +#[cfg(feature = "rt-full")] +mod task; + +mod typed; +pub use self::typed::TypedExecutor; + +#[cfg(feature = "rt-full")] +mod util; + +#[cfg(all(not(feature = "blocking"), feature = "rt-full"))] +mod blocking; +#[cfg(feature = "blocking")] +pub mod blocking; + +#[cfg(feature = "rt-current-thread")] +pub mod current_thread; + +#[cfg(feature = "rt-full")] +pub mod thread_pool; + +pub use futures_util::future::RemoteHandle; diff --git a/tokio-executor/src/park/mod.rs b/tokio/src/executor/park/mod.rs similarity index 100% rename from tokio-executor/src/park/mod.rs rename to tokio/src/executor/park/mod.rs diff --git a/tokio-executor/src/park/thread.rs b/tokio/src/executor/park/thread.rs similarity index 97% rename from tokio-executor/src/park/thread.rs rename to tokio/src/executor/park/thread.rs index 1b9b2c563..af3d632b7 100644 --- a/tokio-executor/src/park/thread.rs +++ b/tokio/src/executor/park/thread.rs @@ -1,6 +1,6 @@ -use crate::loom::sync::atomic::AtomicUsize; -use crate::loom::sync::{Arc, Condvar, Mutex}; -use crate::park::{Park, Unpark}; +use crate::executor::loom::sync::atomic::AtomicUsize; +use crate::executor::loom::sync::{Arc, Condvar, Mutex}; +use crate::executor::park::{Park, Unpark}; use std::marker::PhantomData; use std::mem; diff --git a/tokio-executor/src/task/core.rs b/tokio/src/executor/task/core.rs similarity index 94% rename from tokio-executor/src/task/core.rs rename to tokio/src/executor/task/core.rs index 9c4e813eb..a63c37e2b 100644 --- a/tokio-executor/src/task/core.rs +++ b/tokio/src/executor/task/core.rs @@ -1,9 +1,9 @@ -use crate::loom::alloc::Track; -use crate::loom::cell::CausalCell; -use crate::task::raw::{self, Vtable}; -use crate::task::state::State; -use crate::task::waker::waker_ref; -use crate::task::Schedule; +use crate::executor::loom::alloc::Track; +use crate::executor::loom::cell::CausalCell; +use crate::executor::task::raw::{self, Vtable}; +use crate::executor::task::state::State; +use crate::executor::task::waker::waker_ref; +use crate::executor::task::Schedule; use std::cell::UnsafeCell; use std::future::Future; diff --git a/tokio-executor/src/task/error.rs b/tokio/src/executor/task/error.rs similarity index 100% rename from tokio-executor/src/task/error.rs rename to tokio/src/executor/task/error.rs diff --git a/tokio-executor/src/task/harness.rs b/tokio/src/executor/task/harness.rs similarity index 98% rename from tokio-executor/src/task/harness.rs rename to tokio/src/executor/task/harness.rs index 15b3b023d..ef2978dc4 100644 --- a/tokio-executor/src/task/harness.rs +++ b/tokio/src/executor/task/harness.rs @@ -1,8 +1,8 @@ -use crate::loom::alloc::Track; -use crate::loom::cell::CausalCheck; -use crate::task::core::{Cell, Core, Header, Trailer}; -use crate::task::state::Snapshot; -use crate::task::{Error, Schedule, Task}; +use crate::executor::loom::alloc::Track; +use crate::executor::loom::cell::CausalCheck; +use crate::executor::task::core::{Cell, Core, Header, Trailer}; +use crate::executor::task::state::Snapshot; +use crate::executor::task::{Error, Schedule, Task}; use std::future::Future; use std::mem::{ManuallyDrop, MaybeUninit}; diff --git a/tokio-executor/src/task/join.rs b/tokio/src/executor/task/join.rs similarity index 95% rename from tokio-executor/src/task/join.rs rename to tokio/src/executor/task/join.rs index bce0faa4c..dc6352f56 100644 --- a/tokio-executor/src/task/join.rs +++ b/tokio/src/executor/task/join.rs @@ -1,5 +1,5 @@ -use crate::loom::alloc::Track; -use crate::task::raw::RawTask; +use crate::executor::loom::alloc::Track; +use crate::executor::task::raw::RawTask; use std::future::Future; use std::marker::PhantomData; diff --git a/tokio-executor/src/task/list.rs b/tokio/src/executor/task/list.rs similarity index 97% rename from tokio-executor/src/task/list.rs rename to tokio/src/executor/task/list.rs index d9e0b44d4..297b31061 100644 --- a/tokio-executor/src/task/list.rs +++ b/tokio/src/executor/task/list.rs @@ -1,4 +1,4 @@ -use crate::task::{Header, Task}; +use crate::executor::task::{Header, Task}; use std::fmt; use std::ptr::NonNull; diff --git a/tokio-executor/src/task/mod.rs b/tokio/src/executor/task/mod.rs similarity index 100% rename from tokio-executor/src/task/mod.rs rename to tokio/src/executor/task/mod.rs diff --git a/tokio-executor/src/task/raw.rs b/tokio/src/executor/task/raw.rs similarity index 96% rename from tokio-executor/src/task/raw.rs rename to tokio/src/executor/task/raw.rs index 49fbb96cf..a9b048fce 100644 --- a/tokio-executor/src/task/raw.rs +++ b/tokio/src/executor/task/raw.rs @@ -1,8 +1,8 @@ -use crate::loom::alloc::Track; -use crate::task::core::Cell; -use crate::task::harness::Harness; -use crate::task::state::{Snapshot, State}; -use crate::task::{Header, Schedule}; +use crate::executor::loom::alloc::Track; +use crate::executor::task::core::Cell; +use crate::executor::task::harness::Harness; +use crate::executor::task::state::{Snapshot, State}; +use crate::executor::task::{Header, Schedule}; use std::future::Future; use std::ptr::NonNull; diff --git a/tokio-executor/src/task/stack.rs b/tokio/src/executor/task/stack.rs similarity index 96% rename from tokio-executor/src/task/stack.rs rename to tokio/src/executor/task/stack.rs index 9c981b4be..843452820 100644 --- a/tokio-executor/src/task/stack.rs +++ b/tokio/src/executor/task/stack.rs @@ -1,5 +1,5 @@ -use crate::loom::sync::atomic::AtomicPtr; -use crate::task::{Header, Task}; +use crate::executor::loom::sync::atomic::AtomicPtr; +use crate::executor::task::{Header, Task}; use std::ptr::{self, NonNull}; use std::sync::atomic::Ordering::{Acquire, Relaxed, Release}; diff --git a/tokio-executor/src/task/state.rs b/tokio/src/executor/task/state.rs similarity index 98% rename from tokio-executor/src/task/state.rs rename to tokio/src/executor/task/state.rs index 4c4bbbb78..81e60526e 100644 --- a/tokio-executor/src/task/state.rs +++ b/tokio/src/executor/task/state.rs @@ -1,4 +1,4 @@ -use crate::loom::sync::atomic::AtomicUsize; +use crate::executor::loom::sync::atomic::AtomicUsize; use std::fmt; use std::sync::atomic::Ordering::{AcqRel, Acquire, Release}; @@ -222,7 +222,7 @@ impl State { /// /// Returns a snapshot of the state **after** the transition. pub(super) fn release_task(&self) -> Snapshot { - use crate::loom::sync::atomic; + use crate::executor::loom::sync::atomic; const DELTA: usize = RELEASED; @@ -281,7 +281,7 @@ impl State { /// /// Returns a snapshot of the state **after** the transition. pub(super) fn complete_join_handle(&self) -> Snapshot { - use crate::loom::sync::atomic; + use crate::executor::loom::sync::atomic; const DELTA: usize = JOIN_INTEREST; @@ -335,7 +335,7 @@ impl State { /// Store the join waker. pub(super) fn store_join_waker(&self) -> Snapshot { - use crate::loom::sync::atomic; + use crate::executor::loom::sync::atomic; const DELTA: usize = JOIN_WAKER; @@ -405,7 +405,7 @@ impl State { /// Returns `true` if the task should be released. pub(super) fn ref_dec(&self) -> bool { - use crate::loom::sync::atomic; + use crate::executor::loom::sync::atomic; let prev = self.val.fetch_sub(WAKER_ONE, Release); let next = Snapshot(prev - WAKER_ONE); diff --git a/tokio-executor/src/task/tests/loom.rs b/tokio/src/executor/task/tests/loom.rs similarity index 98% rename from tokio-executor/src/task/tests/loom.rs rename to tokio/src/executor/task/tests/loom.rs index dc2ae942c..53539987f 100644 --- a/tokio-executor/src/task/tests/loom.rs +++ b/tokio/src/executor/task/tests/loom.rs @@ -1,5 +1,5 @@ -use crate::task; -use crate::tests::loom_schedule::LoomSchedule; +use crate::executor::task; +use crate::executor::tests::loom_schedule::LoomSchedule; use tokio_test::{assert_err, assert_ok}; diff --git a/tokio-executor/src/task/tests/mod.rs b/tokio/src/executor/task/tests/mod.rs similarity index 100% rename from tokio-executor/src/task/tests/mod.rs rename to tokio/src/executor/task/tests/mod.rs diff --git a/tokio-executor/src/task/tests/task.rs b/tokio/src/executor/task/tests/task.rs similarity index 98% rename from tokio-executor/src/task/tests/task.rs rename to tokio/src/executor/task/tests/task.rs index 6f6e0ede9..76319b8df 100644 --- a/tokio-executor/src/task/tests/task.rs +++ b/tokio/src/executor/task/tests/task.rs @@ -1,10 +1,9 @@ -use crate::task::{self, Header}; +use crate::executor::task::{self, Header}; +use crate::executor::tests::backoff::*; +use crate::executor::tests::mock_schedule::{mock, Mock}; +use crate::executor::tests::track_drop::track_drop; +use crate::sync::oneshot; -use crate::tests::backoff::*; -use crate::tests::mock_schedule::{mock, Mock}; -use crate::tests::track_drop::track_drop; - -use tokio::sync::oneshot; use tokio_test::task::spawn; use tokio_test::{assert_pending, assert_ready_err, assert_ready_ok}; diff --git a/tokio-executor/src/task/waker.rs b/tokio/src/executor/task/waker.rs similarity index 96% rename from tokio-executor/src/task/waker.rs rename to tokio/src/executor/task/waker.rs index c47f13665..11bb135fa 100644 --- a/tokio-executor/src/task/waker.rs +++ b/tokio/src/executor/task/waker.rs @@ -1,5 +1,5 @@ -use crate::task::harness::Harness; -use crate::task::{Header, Schedule}; +use crate::executor::task::harness::Harness; +use crate::executor::task::{Header, Schedule}; use std::future::Future; use std::marker::PhantomData; diff --git a/tokio-executor/src/tests/backoff.rs b/tokio/src/executor/tests/backoff.rs similarity index 100% rename from tokio-executor/src/tests/backoff.rs rename to tokio/src/executor/tests/backoff.rs diff --git a/tokio-executor/src/tests/loom_oneshot.rs b/tokio/src/executor/tests/loom_oneshot.rs similarity index 100% rename from tokio-executor/src/tests/loom_oneshot.rs rename to tokio/src/executor/tests/loom_oneshot.rs diff --git a/tokio-executor/src/tests/loom_schedule.rs b/tokio/src/executor/tests/loom_schedule.rs similarity index 96% rename from tokio-executor/src/tests/loom_schedule.rs rename to tokio/src/executor/tests/loom_schedule.rs index d3f932284..7999dd974 100644 --- a/tokio-executor/src/tests/loom_schedule.rs +++ b/tokio/src/executor/tests/loom_schedule.rs @@ -1,4 +1,4 @@ -use crate::task::{Schedule, Task}; +use crate::executor::task::{Schedule, Task}; use loom::sync::Notify; use std::collections::VecDeque; diff --git a/tokio-executor/src/tests/mock_park.rs b/tokio/src/executor/tests/mock_park.rs similarity index 96% rename from tokio-executor/src/tests/mock_park.rs rename to tokio/src/executor/tests/mock_park.rs index cd36fdf96..2bc9edf5e 100644 --- a/tokio-executor/src/tests/mock_park.rs +++ b/tokio/src/executor/tests/mock_park.rs @@ -1,6 +1,6 @@ #![allow(warnings)] -use crate::park::{Park, Unpark}; +use crate::executor::park::{Park, Unpark}; use std::collections::HashMap; use std::sync::atomic::{AtomicBool, Ordering::SeqCst}; diff --git a/tokio-executor/src/tests/mock_schedule.rs b/tokio/src/executor/tests/mock_schedule.rs similarity index 98% rename from tokio-executor/src/tests/mock_schedule.rs rename to tokio/src/executor/tests/mock_schedule.rs index 6f1441b08..f105d40c5 100644 --- a/tokio-executor/src/tests/mock_schedule.rs +++ b/tokio/src/executor/tests/mock_schedule.rs @@ -1,6 +1,6 @@ #![allow(warnings)] -use crate::task::{Header, Schedule, Task}; +use crate::executor::task::{Header, Schedule, Task}; use std::collections::VecDeque; use std::sync::Mutex; diff --git a/tokio-executor/src/tests/mod.rs b/tokio/src/executor/tests/mod.rs similarity index 100% rename from tokio-executor/src/tests/mod.rs rename to tokio/src/executor/tests/mod.rs diff --git a/tokio-executor/src/tests/track_drop.rs b/tokio/src/executor/tests/track_drop.rs similarity index 100% rename from tokio-executor/src/tests/track_drop.rs rename to tokio/src/executor/tests/track_drop.rs diff --git a/tokio-executor/src/thread_pool/builder.rs b/tokio/src/executor/thread_pool/builder.rs similarity index 89% rename from tokio-executor/src/thread_pool/builder.rs rename to tokio/src/executor/thread_pool/builder.rs index 394bda313..7955e2864 100644 --- a/tokio-executor/src/thread_pool/builder.rs +++ b/tokio/src/executor/thread_pool/builder.rs @@ -1,9 +1,9 @@ -use crate::loom::sync::Arc; -use crate::loom::sys::num_cpus; -use crate::loom::thread; -use crate::park::Park; -use crate::thread_pool::park::DefaultPark; -use crate::thread_pool::{shutdown, worker, worker::Worker, Spawner, ThreadPool}; +use crate::executor::loom::sync::Arc; +use crate::executor::loom::sys::num_cpus; +use crate::executor::loom::thread; +use crate::executor::park::Park; +use crate::executor::thread_pool::park::DefaultPark; +use crate::executor::thread_pool::{shutdown, worker, worker::Worker, Spawner, ThreadPool}; use std::{fmt, usize}; @@ -48,7 +48,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_executor::thread_pool::Builder; + /// use tokio::executor::thread_pool::Builder; /// /// let thread_pool = Builder::new() /// .num_threads(4) @@ -67,7 +67,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_executor::thread_pool::Builder; + /// use tokio::executor::thread_pool::Builder; /// /// let thread_pool = Builder::new() /// .name("my-pool") @@ -89,7 +89,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_executor::thread_pool::Builder; + /// use tokio::executor::thread_pool::Builder; /// /// let thread_pool = Builder::new() /// .stack_size(32 * 1024) @@ -109,7 +109,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_executor::thread_pool::Builder; + /// use tokio::executor::thread_pool::Builder; /// /// let thread_pool = Builder::new() /// .around_worker(|index, work| { @@ -134,7 +134,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_executor::thread_pool::Builder; + /// use tokio::executor::thread_pool::Builder; /// /// let thread_pool = Builder::new() /// .build(); @@ -188,7 +188,7 @@ impl Builder { }) as Box }; - let mut blocking = crate::blocking::Builder::default(); + let mut blocking = crate::executor::blocking::Builder::default(); blocking.name(self.name.clone()); if let Some(ss) = self.stack_size { blocking.stack_size(ss); @@ -203,11 +203,11 @@ impl Builder { // Spawn threads for each worker for worker in workers { - crate::blocking::Pool::spawn(&blocking, launch_worker(worker)) + crate::executor::blocking::Pool::spawn(&blocking, launch_worker(worker)) } let spawner = Spawner::new(pool); - let blocking = crate::blocking::PoolWaiter::from(blocking); + let blocking = crate::executor::blocking::PoolWaiter::from(blocking); ThreadPool::from_parts(spawner, shutdown_rx, blocking) } } @@ -242,7 +242,7 @@ impl

Park for BoxedPark

where P: Park, { - type Unpark = Box; + type Unpark = Box; type Error = P::Error; fn unpark(&self) -> Self::Unpark { diff --git a/tokio-executor/src/thread_pool/current.rs b/tokio/src/executor/thread_pool/current.rs similarity index 93% rename from tokio-executor/src/thread_pool/current.rs rename to tokio/src/executor/thread_pool/current.rs index dddad7601..6910dca1e 100644 --- a/tokio-executor/src/thread_pool/current.rs +++ b/tokio/src/executor/thread_pool/current.rs @@ -1,6 +1,6 @@ -use crate::loom::sync::Arc; -use crate::park::Unpark; -use crate::thread_pool::{worker, Owned}; +use crate::executor::loom::sync::Arc; +use crate::executor::park::Unpark; +use crate::executor::thread_pool::{worker, Owned}; use std::cell::Cell; use std::ptr; diff --git a/tokio-executor/src/thread_pool/idle.rs b/tokio/src/executor/thread_pool/idle.rs similarity index 98% rename from tokio-executor/src/thread_pool/idle.rs rename to tokio/src/executor/thread_pool/idle.rs index acf80df87..0fae29bf5 100644 --- a/tokio-executor/src/thread_pool/idle.rs +++ b/tokio/src/executor/thread_pool/idle.rs @@ -1,7 +1,7 @@ //! Coordinates idling workers -use crate::loom::sync::atomic::AtomicUsize; -use crate::loom::sync::Mutex; +use crate::executor::loom::sync::atomic::AtomicUsize; +use crate::executor::loom::sync::Mutex; use std::fmt; use std::sync::atomic::Ordering::{self, AcqRel, Relaxed, SeqCst}; diff --git a/tokio-executor/src/thread_pool/join.rs b/tokio/src/executor/thread_pool/join.rs similarity index 89% rename from tokio-executor/src/thread_pool/join.rs rename to tokio/src/executor/thread_pool/join.rs index ffa85eb3e..e066882a3 100644 --- a/tokio-executor/src/thread_pool/join.rs +++ b/tokio/src/executor/thread_pool/join.rs @@ -1,6 +1,6 @@ -use crate::park::Unpark; -use crate::task; -use crate::thread_pool::Shared; +use crate::executor::park::Unpark; +use crate::executor::task; +use crate::executor::thread_pool::Shared; use std::fmt; use std::future::Future; diff --git a/tokio-executor/src/thread_pool/mod.rs b/tokio/src/executor/thread_pool/mod.rs similarity index 96% rename from tokio-executor/src/thread_pool/mod.rs rename to tokio/src/executor/thread_pool/mod.rs index 767625550..bab594ef7 100644 --- a/tokio-executor/src/thread_pool/mod.rs +++ b/tokio/src/executor/thread_pool/mod.rs @@ -38,7 +38,7 @@ mod worker; mod tests; // Re-export `task::Error` -pub use crate::task::Error; +pub use crate::executor::task::Error; // These exports are used in tests #[cfg(test)] diff --git a/tokio-executor/src/thread_pool/owned.rs b/tokio/src/executor/thread_pool/owned.rs similarity index 94% rename from tokio-executor/src/thread_pool/owned.rs rename to tokio/src/executor/thread_pool/owned.rs index 740ee0439..f0aece571 100644 --- a/tokio-executor/src/thread_pool/owned.rs +++ b/tokio/src/executor/thread_pool/owned.rs @@ -1,6 +1,6 @@ -use crate::task::{self, Task}; -use crate::thread_pool::{queue, Shared}; -use crate::util::FastRand; +use crate::executor::task::{self, Task}; +use crate::executor::thread_pool::{queue, Shared}; +use crate::executor::util::FastRand; use std::cell::Cell; diff --git a/tokio-executor/src/thread_pool/park.rs b/tokio/src/executor/thread_pool/park.rs similarity index 97% rename from tokio-executor/src/thread_pool/park.rs rename to tokio/src/executor/thread_pool/park.rs index bc3497684..225d21db9 100644 --- a/tokio-executor/src/thread_pool/park.rs +++ b/tokio/src/executor/thread_pool/park.rs @@ -1,6 +1,6 @@ -use crate::loom::sync::atomic::AtomicUsize; -use crate::loom::sync::{Arc, Condvar, Mutex}; -use crate::park::{Park, Unpark}; +use crate::executor::loom::sync::atomic::AtomicUsize; +use crate::executor::loom::sync::{Arc, Condvar, Mutex}; +use crate::executor::park::{Park, Unpark}; use std::error::Error; use std::fmt; diff --git a/tokio-executor/src/thread_pool/pool.rs b/tokio/src/executor/thread_pool/pool.rs similarity index 83% rename from tokio-executor/src/thread_pool/pool.rs rename to tokio/src/executor/thread_pool/pool.rs index 6b1e302dd..1da4239be 100644 --- a/tokio-executor/src/thread_pool/pool.rs +++ b/tokio/src/executor/thread_pool/pool.rs @@ -1,6 +1,6 @@ -use crate::blocking::PoolWaiter; -use crate::thread_pool::{shutdown, Builder, JoinHandle, Spawner}; -use crate::Executor; +use crate::executor::blocking::PoolWaiter; +use crate::executor::thread_pool::{shutdown, Builder, JoinHandle, Spawner}; +use crate::executor::Executor; use std::fmt; use std::future::Future; @@ -67,9 +67,9 @@ impl ThreadPool { where F: Future, { - crate::global::with_threadpool(self, || { - let mut enter = crate::enter().expect("attempting to block while on a Tokio executor"); - crate::blocking::with_pool(self.spawner.blocking_pool(), || enter.block_on(future)) + crate::executor::global::with_threadpool(self, || { + let mut enter = crate::executor::enter().expect("attempting to block while on a Tokio executor"); + crate::executor::blocking::with_pool(self.spawner.blocking_pool(), || enter.block_on(future)) }) } @@ -92,7 +92,7 @@ impl Executor for &ThreadPool { fn spawn( &mut self, future: std::pin::Pin + Send>>, - ) -> Result<(), crate::SpawnError> { + ) -> Result<(), crate::executor::SpawnError> { ThreadPool::spawn_background(self, future); Ok(()) } diff --git a/tokio-executor/src/thread_pool/queue/global.rs b/tokio/src/executor/thread_pool/queue/global.rs similarity index 97% rename from tokio-executor/src/thread_pool/queue/global.rs rename to tokio/src/executor/thread_pool/queue/global.rs index 2c98ffe92..d5e6575f1 100644 --- a/tokio-executor/src/thread_pool/queue/global.rs +++ b/tokio/src/executor/thread_pool/queue/global.rs @@ -1,6 +1,6 @@ -use crate::loom::sync::atomic::AtomicUsize; -use crate::loom::sync::Mutex; -use crate::task::{Header, Task}; +use crate::executor::loom::sync::atomic::AtomicUsize; +use crate::executor::loom::sync::Mutex; +use crate::executor::task::{Header, Task}; use std::ptr::{self, NonNull}; use std::sync::atomic::Ordering::{Acquire, Release}; diff --git a/tokio-executor/src/thread_pool/queue/inject.rs b/tokio/src/executor/thread_pool/queue/inject.rs similarity index 87% rename from tokio-executor/src/thread_pool/queue/inject.rs rename to tokio/src/executor/thread_pool/queue/inject.rs index faa891f15..dbad65fd3 100644 --- a/tokio-executor/src/thread_pool/queue/inject.rs +++ b/tokio/src/executor/thread_pool/queue/inject.rs @@ -1,6 +1,6 @@ -use crate::loom::sync::Arc; -use crate::task::Task; -use crate::thread_pool::queue::Cluster; +use crate::executor::loom::sync::Arc; +use crate::executor::task::Task; +use crate::executor::thread_pool::queue::Cluster; pub(crate) struct Inject { cluster: Arc>, diff --git a/tokio-executor/src/thread_pool/queue/local.rs b/tokio/src/executor/thread_pool/queue/local.rs similarity index 97% rename from tokio-executor/src/thread_pool/queue/local.rs rename to tokio/src/executor/thread_pool/queue/local.rs index 4de397b9e..e3323cb48 100644 --- a/tokio-executor/src/thread_pool/queue/local.rs +++ b/tokio/src/executor/thread_pool/queue/local.rs @@ -1,8 +1,8 @@ -use crate::loom::cell::{CausalCell, CausalCheck}; -use crate::loom::sync::atomic::{self, AtomicU32}; -use crate::task::Task; -use crate::thread_pool::queue::global; -use crate::thread_pool::LOCAL_QUEUE_CAPACITY; +use crate::executor::loom::cell::{CausalCell, CausalCheck}; +use crate::executor::loom::sync::atomic::{self, AtomicU32}; +use crate::executor::task::Task; +use crate::executor::thread_pool::queue::global; +use crate::executor::thread_pool::LOCAL_QUEUE_CAPACITY; use std::fmt; use std::mem::MaybeUninit; diff --git a/tokio-executor/src/thread_pool/queue/mod.rs b/tokio/src/executor/thread_pool/queue/mod.rs similarity index 96% rename from tokio-executor/src/thread_pool/queue/mod.rs rename to tokio/src/executor/thread_pool/queue/mod.rs index 88633ee39..e873c31a9 100644 --- a/tokio-executor/src/thread_pool/queue/mod.rs +++ b/tokio/src/executor/thread_pool/queue/mod.rs @@ -8,7 +8,7 @@ mod worker; pub(crate) use self::inject::Inject; pub(crate) use self::worker::Worker; -use crate::loom::sync::Arc; +use crate::executor::loom::sync::Arc; pub(crate) fn build(workers: usize) -> Vec> { let local: Vec<_> = (0..workers).map(|_| local::Queue::new()).collect(); diff --git a/tokio-executor/src/thread_pool/queue/worker.rs b/tokio/src/executor/thread_pool/queue/worker.rs similarity index 96% rename from tokio-executor/src/thread_pool/queue/worker.rs rename to tokio/src/executor/thread_pool/queue/worker.rs index d2248dc2c..2cd34a97f 100644 --- a/tokio-executor/src/thread_pool/queue/worker.rs +++ b/tokio/src/executor/thread_pool/queue/worker.rs @@ -1,8 +1,6 @@ -use crate::task::Task; -use crate::thread_pool::queue::{local, Cluster, Inject}; - -// Loom primitive -use crate::loom::sync::Arc; +use crate::executor::loom::sync::Arc; +use crate::executor::task::Task; +use crate::executor::thread_pool::queue::{local, Cluster, Inject}; use std::cell::Cell; use std::fmt; diff --git a/tokio-executor/src/thread_pool/set.rs b/tokio/src/executor/thread_pool/set.rs similarity index 90% rename from tokio-executor/src/thread_pool/set.rs rename to tokio/src/executor/thread_pool/set.rs index 2ff92d75f..dddd50e88 100644 --- a/tokio-executor/src/thread_pool/set.rs +++ b/tokio/src/executor/thread_pool/set.rs @@ -2,13 +2,13 @@ //! //! - Attempt to spin. -use crate::loom::rand::seed; -use crate::loom::sync::Arc; -use crate::park::Unpark; -use crate::task::{self, Task}; -use crate::thread_pool::{current, queue, BoxFuture, Idle, JoinHandle, Owned, Shared}; -use crate::util::{CachePadded, FastRand}; -use crate::{Executor, SpawnError}; +use crate::executor::loom::rand::seed; +use crate::executor::loom::sync::Arc; +use crate::executor::park::Unpark; +use crate::executor::task::{self, Task}; +use crate::executor::thread_pool::{current, queue, BoxFuture, Idle, JoinHandle, Owned, Shared}; +use crate::executor::util::{CachePadded, FastRand}; +use crate::executor::{Executor, SpawnError}; use std::cell::UnsafeCell; use std::future::Future; @@ -30,7 +30,7 @@ where idle: Idle, /// Pool where blocking tasks should be spawned. - pub(crate) blocking: Arc, + pub(crate) blocking: Arc, } unsafe impl Send for Set

{} @@ -44,7 +44,7 @@ where pub(crate) fn new( num_workers: usize, mut mk_unpark: F, - blocking: Arc, + blocking: Arc, ) -> Self where F: FnMut(usize) -> P, @@ -113,7 +113,7 @@ where self.schedule(task); } - pub(super) fn blocking_pool(&self) -> &Arc { + pub(super) fn blocking_pool(&self) -> &Arc { &self.blocking } diff --git a/tokio-executor/src/thread_pool/shared.rs b/tokio/src/executor/thread_pool/shared.rs similarity index 94% rename from tokio-executor/src/thread_pool/shared.rs rename to tokio/src/executor/thread_pool/shared.rs index b717493c2..bf19e1971 100644 --- a/tokio-executor/src/thread_pool/shared.rs +++ b/tokio/src/executor/thread_pool/shared.rs @@ -1,6 +1,6 @@ -use crate::park::Unpark; -use crate::task::{self, Schedule, Task}; -use crate::thread_pool::worker; +use crate::executor::park::Unpark; +use crate::executor::task::{self, Schedule, Task}; +use crate::executor::thread_pool::worker; use std::ptr; diff --git a/tokio-executor/src/thread_pool/shutdown.rs b/tokio/src/executor/thread_pool/shutdown.rs similarity index 93% rename from tokio-executor/src/thread_pool/shutdown.rs rename to tokio/src/executor/thread_pool/shutdown.rs index c0609bde4..40d8f04ac 100644 --- a/tokio-executor/src/thread_pool/shutdown.rs +++ b/tokio/src/executor/thread_pool/shutdown.rs @@ -3,7 +3,7 @@ //! Each worker holds the `Sender` half. When all the `Sender` halves are //! dropped, the `Receiver` receives a notification. -use crate::loom::sync::Arc; +use crate::executor::loom::sync::Arc; use tokio_sync::oneshot; @@ -28,7 +28,7 @@ pub(super) fn channel() -> (Sender, Receiver) { impl Receiver { /// Block the current thread until all `Sender` handles drop. pub(crate) fn wait(&mut self) { - use crate::enter; + use crate::executor::enter; let mut e = match enter() { Ok(e) => e, diff --git a/tokio-executor/src/thread_pool/spawner.rs b/tokio/src/executor/thread_pool/spawner.rs similarity index 88% rename from tokio-executor/src/thread_pool/spawner.rs rename to tokio/src/executor/thread_pool/spawner.rs index 79eff2739..b8d1d115f 100644 --- a/tokio-executor/src/thread_pool/spawner.rs +++ b/tokio/src/executor/thread_pool/spawner.rs @@ -1,6 +1,6 @@ -use crate::loom::sync::Arc; -use crate::park::Unpark; -use crate::thread_pool::{worker, JoinHandle}; +use crate::executor::loom::sync::Arc; +use crate::executor::park::Unpark; +use crate::executor::thread_pool::{worker, JoinHandle}; use std::fmt; use std::future::Future; @@ -44,7 +44,7 @@ impl Spawner { self.workers.spawn_background(future); } - pub(super) fn blocking_pool(&self) -> &Arc { + pub(super) fn blocking_pool(&self) -> &Arc { self.workers.blocking_pool() } diff --git a/tokio-executor/src/thread_pool/tests/loom_pool.rs b/tokio/src/executor/thread_pool/tests/loom_pool.rs similarity index 90% rename from tokio-executor/src/thread_pool/tests/loom_pool.rs rename to tokio/src/executor/thread_pool/tests/loom_pool.rs index 9d3cd64fc..55da54d09 100644 --- a/tokio-executor/src/thread_pool/tests/loom_pool.rs +++ b/tokio/src/executor/thread_pool/tests/loom_pool.rs @@ -1,9 +1,9 @@ -use crate::loom::sync::atomic::Ordering::{Acquire, Relaxed, Release}; -use crate::loom::sync::atomic::{AtomicBool, AtomicUsize}; -use crate::loom::sync::{Arc, Mutex}; use crate::spawn; -use crate::tests::loom_oneshot as oneshot; -use crate::thread_pool::ThreadPool; +use crate::executor::loom::sync::atomic::Ordering::{Acquire, Relaxed, Release}; +use crate::executor::loom::sync::atomic::{AtomicBool, AtomicUsize}; +use crate::executor::loom::sync::{Arc, Mutex}; +use crate::executor::tests::loom_oneshot as oneshot; +use crate::executor::thread_pool::ThreadPool; use std::future::Future; @@ -99,7 +99,7 @@ fn gated() -> impl Future { } fn gated2(thread: bool) -> impl Future { - use crate::loom::thread; + use crate::executor::loom::thread; use futures_util::future::poll_fn; use std::sync::Arc; use std::task::Poll; diff --git a/tokio-executor/src/thread_pool/tests/loom_queue.rs b/tokio/src/executor/thread_pool/tests/loom_queue.rs similarity index 91% rename from tokio-executor/src/thread_pool/tests/loom_queue.rs rename to tokio/src/executor/thread_pool/tests/loom_queue.rs index 1721727be..8b0214a3d 100644 --- a/tokio-executor/src/thread_pool/tests/loom_queue.rs +++ b/tokio/src/executor/thread_pool/tests/loom_queue.rs @@ -1,6 +1,6 @@ -use crate::task::{self, Task}; -use crate::tests::mock_schedule::{Noop, NOOP_SCHEDULE}; -use crate::thread_pool::queue; +use crate::executor::task::{self, Task}; +use crate::executor::tests::mock_schedule::{Noop, NOOP_SCHEDULE}; +use crate::executor::thread_pool::queue; use loom::thread; diff --git a/tokio-executor/src/thread_pool/tests/mod.rs b/tokio/src/executor/thread_pool/tests/mod.rs similarity index 100% rename from tokio-executor/src/thread_pool/tests/mod.rs rename to tokio/src/executor/thread_pool/tests/mod.rs diff --git a/tokio-executor/src/thread_pool/tests/queue.rs b/tokio/src/executor/thread_pool/tests/queue.rs similarity index 97% rename from tokio-executor/src/thread_pool/tests/queue.rs rename to tokio/src/executor/thread_pool/tests/queue.rs index 04cfa1536..be89d94d2 100644 --- a/tokio-executor/src/thread_pool/tests/queue.rs +++ b/tokio/src/executor/thread_pool/tests/queue.rs @@ -1,6 +1,6 @@ -use crate::task::{self, Task}; -use crate::tests::mock_schedule::{Noop, NOOP_SCHEDULE}; -use crate::thread_pool::{queue, LOCAL_QUEUE_CAPACITY}; +use crate::executor::task::{self, Task}; +use crate::executor::tests::mock_schedule::{Noop, NOOP_SCHEDULE}; +use crate::executor::thread_pool::{queue, LOCAL_QUEUE_CAPACITY}; macro_rules! assert_pop { ($q:expr, $expect:expr) => { diff --git a/tokio-executor/src/thread_pool/tests/worker.rs b/tokio/src/executor/thread_pool/tests/worker.rs similarity index 83% rename from tokio-executor/src/thread_pool/tests/worker.rs rename to tokio/src/executor/thread_pool/tests/worker.rs index c41633506..dc132ab76 100644 --- a/tokio-executor/src/thread_pool/tests/worker.rs +++ b/tokio/src/executor/thread_pool/tests/worker.rs @@ -1,5 +1,5 @@ -use crate::tests::track_drop::track_drop; -use crate::thread_pool; +use crate::executor::tests::track_drop::track_drop; +use crate::executor::thread_pool; use tokio_test::assert_ok; @@ -9,8 +9,8 @@ macro_rules! pool { (pool, w.remove(0), w.remove(0), mock_park) }}; (! $n:expr) => {{ - let mut mock_park = crate::tests::mock_park::MockPark::new(); - let blocking = std::sync::Arc::new(crate::blocking::Pool::default()); + let mut mock_park = crate::executor::tests::mock_park::MockPark::new(); + let blocking = std::sync::Arc::new(crate::executor::blocking::Pool::default()); let (pool, workers) = thread_pool::create_pool($n, |index| mock_park.mk_park(index), blocking); (pool, workers, mock_park) @@ -40,7 +40,7 @@ fn execute_single_task() { #[test] fn task_migrates() { use std::sync::mpsc; - use tokio::sync::oneshot; + use crate::sync::oneshot; let (p, mut w0, mut w1, ..) = pool!(2); let (tx1, rx1) = oneshot::channel(); diff --git a/tokio-executor/src/thread_pool/worker.rs b/tokio/src/executor/thread_pool/worker.rs similarity index 95% rename from tokio-executor/src/thread_pool/worker.rs rename to tokio/src/executor/thread_pool/worker.rs index 97571beb2..7fbe6589b 100644 --- a/tokio-executor/src/thread_pool/worker.rs +++ b/tokio/src/executor/thread_pool/worker.rs @@ -1,12 +1,12 @@ -use crate::loom::sync::Arc; -use crate::park::{Park, Unpark}; -use crate::task::Task; -use crate::thread_pool::{current, Owned, Shared}; +use crate::executor::loom::sync::Arc; +use crate::executor::park::{Park, Unpark}; +use crate::executor::task::Task; +use crate::executor::thread_pool::{current, Owned, Shared}; use std::time::Duration; // TODO: remove this re-export -pub(super) use crate::thread_pool::set::Set; +pub(super) use crate::executor::thread_pool::set::Set; pub(crate) struct Worker { /// Entry in the set of workers. @@ -19,7 +19,7 @@ pub(crate) struct Worker { pub(crate) fn create_set( pool_size: usize, mk_park: F, - blocking: Arc, + blocking: Arc, ) -> (Arc>, Vec>) where P: Send + Park, @@ -78,10 +78,10 @@ where // Track the current worker current::set(&pool, index, || { - let _enter = crate::enter().expect("executor already running on thread"); + let _enter = crate::executor::enter().expect("executor already running on thread"); - crate::with_default(&mut executor, || { - crate::blocking::with_pool(blocking, || entry.run(park)) + crate::executor::with_default(&mut executor, || { + crate::executor::blocking::with_pool(blocking, || entry.run(park)) }) }); } diff --git a/tokio-executor/src/typed.rs b/tokio/src/executor/typed.rs similarity index 97% rename from tokio-executor/src/typed.rs rename to tokio/src/executor/typed.rs index ae22cec20..e7cbe373b 100644 --- a/tokio-executor/src/typed.rs +++ b/tokio/src/executor/typed.rs @@ -1,4 +1,4 @@ -use crate::SpawnError; +use crate::executor::SpawnError; /// A value that spawns futures of a specific type. /// @@ -87,7 +87,7 @@ pub trait TypedExecutor { /// # Examples /// /// ```rust - /// use tokio_executor::TypedExecutor; + /// use tokio::executor::TypedExecutor; /// /// use std::future::Future; /// use std::pin::Pin; @@ -131,7 +131,7 @@ pub trait TypedExecutor { /// # Examples /// /// ```rust - /// use tokio_executor::TypedExecutor; + /// use tokio::executor::TypedExecutor; /// /// use std::future::Future; /// use std::pin::Pin; diff --git a/tokio-executor/src/util/mod.rs b/tokio/src/executor/util/mod.rs similarity index 100% rename from tokio-executor/src/util/mod.rs rename to tokio/src/executor/util/mod.rs diff --git a/tokio-executor/src/util/pad.rs b/tokio/src/executor/util/pad.rs similarity index 100% rename from tokio-executor/src/util/pad.rs rename to tokio/src/executor/util/pad.rs diff --git a/tokio-executor/src/util/rand.rs b/tokio/src/executor/util/rand.rs similarity index 100% rename from tokio-executor/src/util/rand.rs rename to tokio/src/executor/util/rand.rs diff --git a/tokio/src/fs/mod.rs b/tokio/src/fs/mod.rs index 2feb5b2c5..c1b4ed71a 100644 --- a/tokio/src/fs/mod.rs +++ b/tokio/src/fs/mod.rs @@ -18,12 +18,9 @@ //! type. Adaptions also extend to traits like `std::io::Read` where methods //! return `std::io::Result`. Be warned that these adapted methods may return //! `std::io::ErrorKind::WouldBlock` if a *worker* thread can not be converted -//! to a *backup* thread immediately. See [tokio-executor] for more details -//! of the threading model and [`blocking`]. +//! to a *backup* thread immediately. //! -//! [`blocking`]: https://docs.rs/tokio-executor/0.2.0-alpha.2/tokio_executor/threadpool/fn.blocking.html //! [`AsyncRead`]: https://docs.rs/tokio-io/0.1/tokio_io/trait.AsyncRead.html -//! [tokio-executor]: https://docs.rs/tokio-executor/0.2.0-alpha.2/tokio_executor/threadpool/index.html pub(crate) mod blocking; @@ -94,5 +91,5 @@ where mod sys { pub(crate) use std::fs::File; - pub(crate) use tokio_executor::blocking::{run, Blocking}; + pub(crate) use crate::executor::blocking::{run, Blocking}; } diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index f5e88b4a5..94eb3072e 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -79,6 +79,11 @@ macro_rules! if_runtime { )*) } +#[cfg(all(loom, test))] +macro_rules! thread_local { + ($($tts:tt)+) => { loom::thread_local!{ $($tts)+ } } +} + #[cfg(feature = "timer")] pub mod clock; @@ -101,10 +106,11 @@ mod loom; pub mod prelude; -#[cfg(feature = "process")] +#[cfg(all(feature = "process", not(loom)))] pub mod process; #[cfg(feature = "signal")] +#[cfg(not(loom))] pub mod signal; pub mod stream; diff --git a/tokio/src/net/addr.rs b/tokio/src/net/addr.rs index 8b782cfa3..812964dae 100644 --- a/tokio/src/net/addr.rs +++ b/tokio/src/net/addr.rs @@ -1,4 +1,4 @@ -use tokio_executor::blocking; +use crate::executor::blocking; use futures_util::future; use std::io; @@ -143,7 +143,7 @@ pub(crate) mod sealed { //! part of the `ToSocketAddrs` public API. The details will change over //! time. - use tokio_executor::blocking::Blocking; + use crate::executor::blocking::Blocking; use futures_core::ready; use std::future::Future; diff --git a/tokio/src/net/driver/mod.rs b/tokio/src/net/driver/mod.rs index b7f33d02e..2b3afc7d8 100644 --- a/tokio/src/net/driver/mod.rs +++ b/tokio/src/net/driver/mod.rs @@ -124,12 +124,12 @@ //! [`PollEvented`]: struct.PollEvented.html //! [`std::io::Read`]: https://doc.rust-lang.org/std/io/trait.Read.html //! [`std::io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html -#[cfg(loom)] +#[cfg(all(loom, test))] macro_rules! loom_thread_local { ($($tts:tt)+) => { loom::thread_local!{ $($tts)+ } } } -#[cfg(not(loom))] +#[cfg(any(not(loom), not(test)))] macro_rules! loom_thread_local { ($($tts:tt)+) => { std::thread_local!{ $($tts)+ } } } diff --git a/tokio/src/net/driver/reactor/mod.rs b/tokio/src/net/driver/reactor/mod.rs index 44443d352..a5325f7dd 100644 --- a/tokio/src/net/driver/reactor/mod.rs +++ b/tokio/src/net/driver/reactor/mod.rs @@ -1,4 +1,5 @@ use super::platform; +use crate::executor::park::{Park, Unpark}; use crate::loom::atomic::{AtomicUsize, Ordering::SeqCst}; mod dispatch; @@ -15,7 +16,6 @@ use std::sync::{Arc, Weak}; use std::task::Waker; use std::time::Duration; use std::{fmt, usize}; -use tokio_executor::park::{Park, Unpark}; /// The core reactor, or event loop. /// diff --git a/tokio/src/runtime/current_thread/builder.rs b/tokio/src/runtime/current_thread/builder.rs index 82fb8e55c..7bf6d73d0 100644 --- a/tokio/src/runtime/current_thread/builder.rs +++ b/tokio/src/runtime/current_thread/builder.rs @@ -1,10 +1,9 @@ +use crate::executor::current_thread::CurrentThread; use crate::net::driver::Reactor; use crate::runtime::current_thread::Runtime; use crate::timer::clock::Clock; use crate::timer::timer::Timer; -use tokio_executor::current_thread::CurrentThread; - use std::io; /// Builds a Single-threaded runtime with custom configuration values. diff --git a/tokio/src/runtime/current_thread/mod.rs b/tokio/src/runtime/current_thread/mod.rs index 4b237d35e..8a2d6028f 100644 --- a/tokio/src/runtime/current_thread/mod.rs +++ b/tokio/src/runtime/current_thread/mod.rs @@ -63,5 +63,5 @@ mod runtime; pub use self::builder::Builder; pub use self::runtime::{Handle, Runtime, RunError}; -pub use tokio_executor::current_thread::spawn; -pub use tokio_executor::current_thread::TaskExecutor; +pub use crate::executor::current_thread::spawn; +pub use crate::executor::current_thread::TaskExecutor; diff --git a/tokio/src/runtime/current_thread/runtime.rs b/tokio/src/runtime/current_thread/runtime.rs index f706c65cd..9912770ad 100644 --- a/tokio/src/runtime/current_thread/runtime.rs +++ b/tokio/src/runtime/current_thread/runtime.rs @@ -1,11 +1,10 @@ +use crate::executor::current_thread::Handle as ExecutorHandle; +use crate::executor::current_thread::{self, CurrentThread}; use crate::net::driver::{self, Reactor}; use crate::runtime::current_thread::Builder; use crate::timer::clock::{self, Clock}; use crate::timer::timer::{self, Timer}; -use tokio_executor::current_thread::Handle as ExecutorHandle; -use tokio_executor::current_thread::{self, CurrentThread}; - use std::error::Error; use std::fmt; use std::future::Future; @@ -38,7 +37,7 @@ impl Handle { /// /// This function panics if the spawn fails. Failure occurs if the `CurrentThread` /// instance of the `Handle` does not exist anymore. - pub fn spawn(&self, future: F) -> Result<(), tokio_executor::SpawnError> + pub fn spawn(&self, future: F) -> Result<(), crate::executor::SpawnError> where F: Future + Send + 'static, { @@ -54,7 +53,7 @@ impl Handle { /// /// This allows a caller to avoid creating the task if the call to `spawn` /// has a high likelihood of failing. - pub fn status(&self) -> Result<(), tokio_executor::SpawnError> { + pub fn status(&self) -> Result<(), crate::executor::SpawnError> { self.0.status() } } @@ -201,7 +200,7 @@ impl Runtime { // to run the provided future, another to install as the default // one). We use the fake one here as the default one. let mut default_executor = current_thread::TaskExecutor::current(); - tokio_executor::with_default(&mut default_executor, || f(executor)) + crate::executor::with_default(&mut default_executor, || f(executor)) }) } } diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index a661923cf..ebaf47ddf 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -19,7 +19,7 @@ //! Creating a [`Runtime`] does the following: //! //! * Spawn a background thread running a [`Reactor`] instance. -//! * Start a [`ThreadPool`] for executing futures. +//! * Start a thread pool for executing futures. //! * Run an instance of `Timer` **per** thread pool worker thread. //! //! The thread pool uses a work-stealing strategy and is configured to start a @@ -124,12 +124,12 @@ //! [timer]: ../timer/index.html //! [`Runtime`]: struct.Runtime.html //! [`Reactor`]: ../reactor/struct.Reactor.html -//! [`ThreadPool`]: https://docs.rs/tokio-executor/0.2.0-alpha.2/tokio_executor/threadpool/struct.ThreadPool.html //! [`run`]: fn.run.html //! [`tokio::spawn`]: ../executor/fn.spawn.html //! [`tokio::main`]: ../../tokio_macros/attr.main.html pub mod current_thread; + #[cfg(feature = "rt-full")] mod threadpool; diff --git a/tokio/src/runtime/threadpool/builder.rs b/tokio/src/runtime/threadpool/builder.rs index 3c94258fa..6d409f8a4 100644 --- a/tokio/src/runtime/threadpool/builder.rs +++ b/tokio/src/runtime/threadpool/builder.rs @@ -1,10 +1,9 @@ +use crate::executor::thread_pool; use crate::net::driver::{self, Reactor}; use crate::runtime::threadpool::{Inner, Runtime}; use crate::timer::clock::{self, Clock}; use crate::timer::timer::{self, Timer}; -use tokio_executor::thread_pool; - use std::sync::{Arc, Mutex}; use std::{fmt, io}; diff --git a/tokio/src/runtime/threadpool/mod.rs b/tokio/src/runtime/threadpool/mod.rs index 2e6924ed7..dad3437bf 100644 --- a/tokio/src/runtime/threadpool/mod.rs +++ b/tokio/src/runtime/threadpool/mod.rs @@ -7,12 +7,12 @@ mod spawner; pub use self::spawner::Spawner; #[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411 -pub use tokio_executor::thread_pool::JoinHandle; +pub use crate::executor::thread_pool::JoinHandle; use crate::net::driver; use crate::timer::timer; -use tokio_executor::thread_pool::ThreadPool; +use crate::executor::thread_pool::ThreadPool; use std::future::Future; use std::io; diff --git a/tokio/src/runtime/threadpool/spawner.rs b/tokio/src/runtime/threadpool/spawner.rs index 204bcc0e4..73daf8bce 100644 --- a/tokio/src/runtime/threadpool/spawner.rs +++ b/tokio/src/runtime/threadpool/spawner.rs @@ -1,7 +1,6 @@ +use crate::executor::thread_pool; use crate::runtime::JoinHandle; -use tokio_executor::thread_pool; - use std::future::Future; /// Spawns futures on the runtime diff --git a/tokio/src/timer/timer/mod.rs b/tokio/src/timer/timer/mod.rs index 80e460de2..df0155d54 100644 --- a/tokio/src/timer/timer/mod.rs +++ b/tokio/src/timer/timer/mod.rs @@ -41,13 +41,12 @@ pub(crate) use self::registration::Registration; mod stack; use self::stack::Stack; +use crate::executor::park::{Park, ParkThread, Unpark}; use crate::timer::atomic::AtomicU64; use crate::timer::clock::Clock; use crate::timer::wheel; use crate::timer::Error; -use tokio_executor::park::{Park, ParkThread, Unpark}; - use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; use std::sync::Arc; diff --git a/tokio-executor/tests/current_thread.rs b/tokio/tests/current_thread.rs similarity index 98% rename from tokio-executor/tests/current_thread.rs rename to tokio/tests/current_thread.rs index 0f69730f3..6a7888842 100644 --- a/tokio-executor/tests/current_thread.rs +++ b/tokio/tests/current_thread.rs @@ -1,9 +1,9 @@ #![warn(rust_2018_idioms)] #![cfg(not(miri))] +use tokio::executor::current_thread::{self, block_on_all, CurrentThread, TaskExecutor}; +use tokio::executor::TypedExecutor; use tokio::sync::oneshot; -use tokio_executor::current_thread::{self, block_on_all, CurrentThread, TaskExecutor}; -use tokio_executor::TypedExecutor; use std::any::Any; use std::cell::{Cell, RefCell}; @@ -100,7 +100,7 @@ mod does_not_set_global_executor_by_default { #[test] fn spawn() { - test(|f| tokio_executor::DefaultExecutor::current().spawn(f)) + test(|f| tokio::executor::DefaultExecutor::current().spawn(f)) } } @@ -547,7 +547,7 @@ struct MyPark { struct MyUnpark; -impl tokio_executor::park::Park for MyPark { +impl tokio::executor::park::Park for MyPark { type Unpark = MyUnpark; type Error = (); @@ -569,7 +569,7 @@ impl tokio_executor::park::Park for MyPark { } } -impl tokio_executor::park::Unpark for MyUnpark { +impl tokio::executor::park::Unpark for MyUnpark { fn unpark(&self) {} } diff --git a/tokio-executor/tests/executor.rs b/tokio/tests/executor.rs similarity index 84% rename from tokio-executor/tests/executor.rs rename to tokio/tests/executor.rs index 3f297807d..e3fd6a5e4 100644 --- a/tokio-executor/tests/executor.rs +++ b/tokio/tests/executor.rs @@ -1,13 +1,13 @@ #![warn(rust_2018_idioms)] -use tokio_executor::{self, DefaultExecutor}; +use tokio::executor::DefaultExecutor; use std::future::Future; use std::pin::Pin; mod out_of_executor_context { use super::*; - use tokio_executor::Executor; + use tokio::executor::Executor; fn test(spawn: F) where diff --git a/tokio-executor/tests/enter.rs b/tokio/tests/executor_enter.rs similarity index 68% rename from tokio-executor/tests/enter.rs rename to tokio/tests/executor_enter.rs index 4d894de0d..17f0e741b 100644 --- a/tokio-executor/tests/enter.rs +++ b/tokio/tests/executor_enter.rs @@ -2,7 +2,7 @@ #[test] fn block_on_ready() { - let mut enter = tokio_executor::enter().unwrap(); + let mut enter = tokio::executor::enter().unwrap(); let val = enter.block_on(async { 123 }); assert_eq!(val, 123); @@ -10,7 +10,7 @@ fn block_on_ready() { #[test] fn block_on_pending() { - let mut enter = tokio_executor::enter().unwrap(); + let mut enter = tokio::executor::enter().unwrap(); let val = enter.block_on(async { 123 }); assert_eq!(val, 123); diff --git a/tokio-executor/tests/global.rs b/tokio/tests/executor_global.rs similarity index 74% rename from tokio-executor/tests/global.rs rename to tokio/tests/executor_global.rs index 5aef0597d..6c14f065b 100644 --- a/tokio-executor/tests/global.rs +++ b/tokio/tests/executor_global.rs @@ -1,4 +1,4 @@ -use tokio_executor::{with_default, DefaultExecutor}; +use tokio::executor::{with_default, DefaultExecutor}; #[test] fn default_executor_is_send_and_sync() { @@ -10,7 +10,7 @@ fn default_executor_is_send_and_sync() { #[test] #[should_panic] fn nested_default_executor_status() { - let _enter = tokio_executor::enter().unwrap(); + let _enter = tokio::executor::enter().unwrap(); let mut executor = DefaultExecutor::current(); let _result = with_default(&mut executor, || ()); diff --git a/tokio/tests/net_driver.rs b/tokio/tests/net_driver.rs index 998bfcc91..687e4aab5 100644 --- a/tokio/tests/net_driver.rs +++ b/tokio/tests/net_driver.rs @@ -61,7 +61,7 @@ fn test_drop_on_notify() { } })); - let _enter = tokio_executor::enter().unwrap(); + let _enter = tokio::executor::enter().unwrap(); { let handle = reactor.handle(); diff --git a/tokio/tests/runtime_current_thread.rs b/tokio/tests/runtime_current_thread.rs index ff742707e..47b2ebc94 100644 --- a/tokio/tests/runtime_current_thread.rs +++ b/tokio/tests/runtime_current_thread.rs @@ -1,5 +1,4 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "default")] use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; @@ -133,6 +132,6 @@ fn racy() { // wait for runtime thread to exit jh.join().unwrap(); - let mut e = tokio_executor::enter().unwrap(); + let mut e = tokio::executor::enter().unwrap(); e.block_on(rx).unwrap(); } diff --git a/tokio/tests/runtime_threaded.rs b/tokio/tests/runtime_threaded.rs index 96f34b988..971562871 100644 --- a/tokio/tests/runtime_threaded.rs +++ b/tokio/tests/runtime_threaded.rs @@ -1,7 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "default")] -use tokio; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; use tokio::runtime::Runtime; @@ -9,7 +7,6 @@ use tokio::sync::oneshot; use tokio::timer::delay; use tokio_test::{assert_err, assert_ok}; -use env_logger; use std::sync::{mpsc, Arc, Mutex}; use std::thread; use std::time::{Duration, Instant}; @@ -146,7 +143,7 @@ fn nested_enter() { let rt = Runtime::new().unwrap(); rt.block_on(async { - assert_err!(tokio_executor::enter()); + assert_err!(tokio::executor::enter()); let res = panic::catch_unwind(move || { let rt = Runtime::new().unwrap(); diff --git a/tokio-executor/tests/thread_pool.rs b/tokio/tests/thread_pool.rs similarity index 98% rename from tokio-executor/tests/thread_pool.rs rename to tokio/tests/thread_pool.rs index adb7b2c4a..9ef4b3336 100644 --- a/tokio-executor/tests/thread_pool.rs +++ b/tokio/tests/thread_pool.rs @@ -1,7 +1,7 @@ #![warn(rust_2018_idioms)] -use tokio_executor::park::{Park, Unpark}; -use tokio_executor::thread_pool::*; +use tokio::executor::park::{Park, Unpark}; +use tokio::executor::thread_pool::*; use futures_util::future::poll_fn; use std::cell::Cell; @@ -210,7 +210,7 @@ fn many_multishot_futures() { } { - let mut e = tokio_executor::enter().unwrap(); + let mut e = tokio::executor::enter().unwrap(); e.block_on(async move { for mut start_tx in start_txs { @@ -232,7 +232,7 @@ fn global_executor_is_configured() { let (signal_tx, signal_rx) = mpsc::channel(); pool.spawn(async move { - tokio_executor::spawn(async move { + tokio::executor::spawn(async move { signal_tx.send(()).unwrap(); }); }); diff --git a/tokio/tests/timer_hammer.rs b/tokio/tests/timer_hammer.rs index b53ff250a..b6800d612 100644 --- a/tokio/tests/timer_hammer.rs +++ b/tokio/tests/timer_hammer.rs @@ -1,11 +1,9 @@ #![warn(rust_2018_idioms)] +use tokio::executor::current_thread::CurrentThread; +use tokio::executor::park::{Park, Unpark, UnparkThread}; use tokio::timer::{Delay, Timer}; -use tokio_executor::current_thread::CurrentThread; -use tokio_executor::park::{Park, Unpark, UnparkThread}; - -use rand; use rand::Rng; use std::cmp; use std::future::Future;