From 3b27dc31d28df93fcc65ed3b744033d4ad4f77cc Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 15 Aug 2019 13:09:02 -0700 Subject: [PATCH] threadpool: move threadpool into tokio-executor (#1452) The threadpool is behind a feature flag. Refs: #1264 --- Cargo.toml | 1 - README.md | 7 +- azure-pipelines.yml | 29 +------ ci/azure-tsan.yml | 2 +- ci/patch.toml | 1 - tokio-executor/Cargo.toml | 28 ++++++ .../benches/blocking.rs | 4 +- .../benches/threadpool.rs | 2 +- .../benches/threadpool_depth.rs | 2 +- tokio-executor/src/lib.rs | 3 + .../src/threadpool}/blocking.rs | 7 +- .../src/threadpool}/builder.rs | 46 +++++----- .../src/threadpool}/callback.rs | 3 +- .../src/threadpool}/config.rs | 3 +- .../src/threadpool/mod.rs | 21 ++--- .../src/threadpool}/park/boxed.rs | 3 +- .../src/threadpool}/park/default_park.rs | 3 +- .../src/threadpool}/park/mod.rs | 0 .../src/threadpool}/pool/backup.rs | 4 +- .../src/threadpool}/pool/backup_stack.rs | 2 +- .../src/threadpool}/pool/mod.rs | 16 ++-- .../src/threadpool}/pool/state.rs | 0 .../src/threadpool}/sender.rs | 30 +++---- .../src/threadpool}/shutdown.rs | 6 +- .../src/threadpool}/task/blocking.rs | 7 +- .../src/threadpool}/task/blocking_state.rs | 3 +- .../src/threadpool}/task/mod.rs | 4 +- .../src/threadpool}/task/state.rs | 0 .../src/threadpool}/thread_pool.rs | 14 +-- .../src/threadpool}/waker.rs | 4 +- .../src/threadpool}/worker/entry.rs | 11 +-- .../src/threadpool}/worker/mod.rs | 19 ++--- .../src/threadpool}/worker/stack.rs | 5 +- .../src/threadpool}/worker/state.rs | 0 .../tests/threadpool.rs | 19 ++--- .../tests/threadpool_blocking.rs | 6 +- .../tests/threadpool_hammer.rs | 2 +- tokio-fs/Cargo.toml | 2 +- tokio-fs/src/lib.rs | 10 ++- tokio-fs/tests/pool/mod.rs | 3 +- tokio-threadpool/CHANGELOG.md | 85 ------------------- tokio-threadpool/Cargo.toml | 43 ---------- tokio-threadpool/LICENSE | 25 ------ tokio-threadpool/README.md | 14 --- tokio/Cargo.toml | 3 +- tokio/src/runtime/mod.rs | 2 +- tokio/src/runtime/threadpool/builder.rs | 6 +- tokio/src/runtime/threadpool/mod.rs | 3 +- tokio/src/runtime/threadpool/task_executor.rs | 2 +- 49 files changed, 166 insertions(+), 349 deletions(-) rename {tokio-threadpool => tokio-executor}/benches/blocking.rs (96%) rename tokio-threadpool/benches/basic.rs => tokio-executor/benches/threadpool.rs (99%) rename tokio-threadpool/benches/depth.rs => tokio-executor/benches/threadpool_depth.rs (97%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/blocking.rs (97%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/builder.rs (92%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/callback.rs (94%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/config.rs (97%) rename tokio-threadpool/src/lib.rs => tokio-executor/src/threadpool/mod.rs (92%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/park/boxed.rs (96%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/park/default_park.rs (98%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/park/mod.rs (100%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/pool/backup.rs (99%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/pool/backup_stack.rs (99%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/pool/mod.rs (98%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/pool/state.rs (100%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/sender.rs (87%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/shutdown.rs (96%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/task/blocking.rs (99%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/task/blocking_state.rs (98%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/task/mod.rs (99%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/task/state.rs (100%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/thread_pool.rs (95%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/waker.rs (91%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/worker/entry.rs (98%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/worker/mod.rs (98%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/worker/stack.rs (99%) rename {tokio-threadpool/src => tokio-executor/src/threadpool}/worker/state.rs (100%) rename {tokio-threadpool => tokio-executor}/tests/threadpool.rs (97%) rename tokio-threadpool/tests/blocking.rs => tokio-executor/tests/threadpool_blocking.rs (99%) rename tokio-threadpool/tests/hammer.rs => tokio-executor/tests/threadpool_hammer.rs (98%) delete mode 100644 tokio-threadpool/CHANGELOG.md delete mode 100644 tokio-threadpool/Cargo.toml delete mode 100644 tokio-threadpool/LICENSE delete mode 100644 tokio-threadpool/README.md diff --git a/Cargo.toml b/Cargo.toml index 5b0a98559..bf1d9e095 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ members = [ "tokio-signal", "tokio-sync", "tokio-test", - "tokio-threadpool", "tokio-timer", "tokio-tcp", "tokio-tls", diff --git a/README.md b/README.md index 0ce81494e..f20ac1f46 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,8 @@ have greater guarantees of stability. The crates included as part of Tokio are: -* [`tokio-executor`]: Task executors and related utilities. +* [`tokio-executor`]: Task executors and related utilities. Includes a + single-threaded executor and a multi-threaded, work-stealing, executor. * [`tokio-fs`]: Filesystem (and standard in / out) APIs. @@ -144,9 +145,6 @@ The crates included as part of Tokio are: * [`tokio-tcp`]: TCP listener and acceptor. -* [`tokio-threadpool`]: Schedules the execution of futures across a pool of - threads. - * [ `tokio-timer`]: Time related APIs. * [`tokio-udp`]: UDP socket. @@ -161,7 +159,6 @@ The crates included as part of Tokio are: [`tokio-macros`]: tokio-macros [`tokio-net`]: tokio-net [`tokio-tcp`]: tokio-tcp -[`tokio-threadpool`]: tokio-threadpool [`tokio-timer`]: tokio-timer [`tokio-udp`]: tokio-udp [`tokio-uds`]: tokio-uds diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4b740f5f9..e48a8a927 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -67,12 +67,12 @@ jobs: tokio-codec: [] tokio-executor: - current-thread + - threadpool tokio-io: - util tokio-sync: - async-traits tokio-macros: [] - # - tokio-threadpool tokio-timer: - async-traits tokio-test: [] @@ -89,33 +89,6 @@ jobs: - tokio-no-features - tokio-with-net -# - template: ci/azure-cargo-check.yml -# parameters: -# name: features -# displayName: Check feature permtuations -# rust: stable -# crates: -# tokio: -# - codec -# - fs -# - io -# - reactor -# - rt-full -# - tcp -# - timer -# - udp -# - uds -# - sync -# tokio-buf: -# - util -# -# # Run async-await tests -# - template: ci/azure-test-nightly.yml -# parameters: -# name: test_nightly -# displayName: Test Async / Await -# rust: $(nightly) -# # # Try cross compiling # - template: ci/azure-cross-compile.yml # parameters: diff --git a/ci/azure-tsan.yml b/ci/azure-tsan.yml index 3666c285c..3ce24ee84 100644 --- a/ci/azure-tsan.yml +++ b/ci/azure-tsan.yml @@ -6,7 +6,7 @@ jobs: Timer: cmd: cargo test -p tokio-timer --test hammer Threadpool: - cmd: cargo test -p tokio-threadpool --tests + 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 d5f2e34d6..2f2aa87dc 100644 --- a/ci/patch.toml +++ b/ci/patch.toml @@ -11,7 +11,6 @@ tokio-macros = { path = "tokio-macros" } tokio-net = { path = "tokio-net" } tokio-signal = { path = "tokio-signal" } tokio-sync = { path = "tokio-sync" } -tokio-threadpool = { path = "tokio-threadpool" } tokio-timer = { path = "tokio-timer" } tokio-tcp = { path = "tokio-tcp" } tokio-tls = { path = "tokio-tls" } diff --git a/tokio-executor/Cargo.toml b/tokio-executor/Cargo.toml index f5bc8ab28..d3edd0272 100644 --- a/tokio-executor/Cargo.toml +++ b/tokio-executor/Cargo.toml @@ -22,11 +22,39 @@ categories = ["concurrency", "asynchronous"] [features] current-thread = ["crossbeam-channel"] +threadpool = [ + "tokio-sync", + "crossbeam-deque", + "crossbeam-queue", + "crossbeam-utils", + "futures-core-preview", + "futures-util-preview", + "num_cpus", + "log", + "lazy_static", + "slab", +] [dependencies] +tokio-sync = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-sync" } + +# current-thread dependencies crossbeam-channel = { version = "0.3.8", optional = true } +# threadpool dependencies +crossbeam-deque = { version = "0.7.0", optional = true } +crossbeam-queue = { version = "0.1.0", optional = true } +crossbeam-utils = { version = "0.6.4", optional = true } +futures-core-preview = { version = "=0.3.0-alpha.18", optional = true } +futures-util-preview = { version = "=0.3.0-alpha.18", optional = true } +num_cpus = { version = "1.2", optional = true } +log = { version = "0.4", optional = true } +lazy_static = { version = "1", optional = true } +slab = { version = "0.4.1", optional = true } + [dev-dependencies] tokio = { version = "=0.2.0-alpha.1", path = "../tokio" } +tokio-test = { version = "=0.2.0-alpha.1", path = "../tokio-test" } futures-core-preview = "=0.3.0-alpha.18" +rand = "0.7" diff --git a/tokio-threadpool/benches/blocking.rs b/tokio-executor/benches/blocking.rs similarity index 96% rename from tokio-threadpool/benches/blocking.rs rename to tokio-executor/benches/blocking.rs index 46e4e0392..6efdf4488 100644 --- a/tokio-threadpool/benches/blocking.rs +++ b/tokio-executor/benches/blocking.rs @@ -8,7 +8,7 @@ const ITER: usize = 1_000; mod blocking { use super::*; use futures::future::*; - use tokio_threadpool::{blocking, Builder}; + use tokio_executor::threadpool::{blocking, Builder}; #[bench] fn cpu_bound(b: &mut test::Bencher) { @@ -39,7 +39,7 @@ mod message_passing { use super::*; use futures::future::*; use futures::sync::oneshot; - use tokio_threadpool::Builder; + use tokio_executor::threadpool::Builder; #[bench] fn cpu_bound(b: &mut test::Bencher) { diff --git a/tokio-threadpool/benches/basic.rs b/tokio-executor/benches/threadpool.rs similarity index 99% rename from tokio-threadpool/benches/basic.rs rename to tokio-executor/benches/threadpool.rs index 9073e0797..3e106a3fe 100644 --- a/tokio-threadpool/benches/basic.rs +++ b/tokio-executor/benches/threadpool.rs @@ -13,7 +13,7 @@ mod threadpool { use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; use std::sync::{mpsc, Arc}; - use tokio_threadpool::*; + use tokio_executor::threadpool::*; #[bench] fn spawn_many(b: &mut test::Bencher) { diff --git a/tokio-threadpool/benches/depth.rs b/tokio-executor/benches/threadpool_depth.rs similarity index 97% rename from tokio-threadpool/benches/depth.rs rename to tokio-executor/benches/threadpool_depth.rs index be6073400..042d2d782 100644 --- a/tokio-threadpool/benches/depth.rs +++ b/tokio-executor/benches/threadpool_depth.rs @@ -8,7 +8,7 @@ const ITER: usize = 20_000; mod us { use futures::future; use std::sync::mpsc; - use tokio_threadpool::*; + use tokio_executor::threadpool::*; #[bench] fn chained_spawn(b: &mut test::Bencher) { diff --git a/tokio-executor/src/lib.rs b/tokio-executor/src/lib.rs index ba56f5671..0523731fc 100644 --- a/tokio-executor/src/lib.rs +++ b/tokio-executor/src/lib.rs @@ -67,6 +67,9 @@ mod typed; #[cfg(feature = "current-thread")] pub mod current_thread; +#[cfg(feature = "threadpool")] +pub mod threadpool; + pub use crate::enter::{enter, exit, Enter, EnterError}; pub use crate::error::SpawnError; pub use crate::executor::Executor; diff --git a/tokio-threadpool/src/blocking.rs b/tokio-executor/src/threadpool/blocking.rs similarity index 97% rename from tokio-threadpool/src/blocking.rs rename to tokio-executor/src/threadpool/blocking.rs index 3b59545c2..f68a337f9 100644 --- a/tokio-threadpool/src/blocking.rs +++ b/tokio-executor/src/threadpool/blocking.rs @@ -1,10 +1,9 @@ -use crate::worker::Worker; +use super::worker::Worker; use futures_core::ready; use std::error::Error; use std::fmt; use std::task::Poll; -use tokio_executor; /// Error raised by `blocking`. pub struct BlockingError { @@ -83,7 +82,7 @@ pub struct BlockingError { /// ```rust /// #![feature(async_await)] /// -/// use tokio_threadpool::{ThreadPool, blocking}; +/// use tokio_executor::threadpool::{ThreadPool, blocking}; /// /// use futures_util::future::poll_fn; /// use std::sync::mpsc; @@ -144,7 +143,7 @@ where // // "Exit" the current executor in case the blocking function wants // to call a different executor. - let ret = tokio_executor::exit(move || f()); + let ret = crate::exit(move || f()); // Try to transition out of blocking mode. This is a fast path that takes // back ownership of the worker if the worker handoff didn't complete yet. diff --git a/tokio-threadpool/src/builder.rs b/tokio-executor/src/threadpool/builder.rs similarity index 92% rename from tokio-threadpool/src/builder.rs rename to tokio-executor/src/threadpool/builder.rs index a7c019eb2..c7a82a2d9 100644 --- a/tokio-threadpool/src/builder.rs +++ b/tokio-executor/src/threadpool/builder.rs @@ -1,10 +1,12 @@ -use crate::callback::Callback; -use crate::config::{Config, MAX_WORKERS}; -use crate::park::{BoxPark, BoxedPark, DefaultPark}; -use crate::pool::{Pool, MAX_BACKUP}; -use crate::shutdown::ShutdownTrigger; -use crate::thread_pool::ThreadPool; -use crate::worker::{self, Worker, WorkerId}; +use super::callback::Callback; +use super::config::{Config, MAX_WORKERS}; +use super::park::{BoxPark, BoxedPark, DefaultPark}; +use super::pool::{Pool, MAX_BACKUP}; +use super::shutdown::ShutdownTrigger; +use super::thread_pool::ThreadPool; +use super::worker::{self, Worker, WorkerId}; +use crate::park::Park; + use crossbeam_deque::Injector; use log::trace; use num_cpus; @@ -14,7 +16,6 @@ use std::error::Error; use std::fmt; use std::sync::Arc; use std::time::Duration; -use tokio_executor::park::Park; /// Builds a thread pool with custom configuration values. /// @@ -34,7 +35,7 @@ use tokio_executor::park::Park; /// ``` /// #![feature(async_await)] /// -/// use tokio_threadpool::Builder; +/// use tokio_executor::threadpool::Builder; /// /// use std::time::Duration; /// @@ -74,7 +75,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// use std::time::Duration; /// /// let thread_pool = Builder::new() @@ -114,7 +115,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// /// let thread_pool = Builder::new() /// .pool_size(4) @@ -142,7 +143,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// /// let thread_pool = Builder::new() /// .max_blocking(200) @@ -168,7 +169,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// use std::time::Duration; /// /// let thread_pool = Builder::new() @@ -190,7 +191,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// /// let thread_pool = Builder::new() /// .panic_handler(|err| std::panic::resume_unwind(err)) @@ -216,7 +217,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// /// let thread_pool = Builder::new() /// .name_prefix("my-pool-") @@ -238,7 +239,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// /// let thread_pool = Builder::new() /// .stack_size(32 * 1024) @@ -258,7 +259,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// /// let thread_pool = Builder::new() /// .around_worker(|worker| { @@ -286,7 +287,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// /// let thread_pool = Builder::new() /// .after_start(|| { @@ -309,7 +310,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// /// let thread_pool = Builder::new() /// .before_stop(|| { @@ -333,13 +334,12 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; + /// use tokio_executor::threadpool::park::DefaultPark; /// # fn decorate(f: F) -> F { f } /// /// let thread_pool = Builder::new() /// .custom_park(|_| { - /// use tokio_threadpool::park::DefaultPark; - /// /// // This is the default park type that the worker would use if we /// // did not customize it. /// let park = DefaultPark::new(); @@ -368,7 +368,7 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_threadpool::Builder; + /// use tokio_executor::threadpool::Builder; /// /// let thread_pool = Builder::new() /// .build(); diff --git a/tokio-threadpool/src/callback.rs b/tokio-executor/src/threadpool/callback.rs similarity index 94% rename from tokio-threadpool/src/callback.rs rename to tokio-executor/src/threadpool/callback.rs index b9d101615..b3a47ddab 100644 --- a/tokio-threadpool/src/callback.rs +++ b/tokio-executor/src/threadpool/callback.rs @@ -1,4 +1,5 @@ -use crate::worker::Worker; +use super::worker::Worker; + use std::fmt; use std::sync::Arc; diff --git a/tokio-threadpool/src/config.rs b/tokio-executor/src/threadpool/config.rs similarity index 97% rename from tokio-threadpool/src/config.rs rename to tokio-executor/src/threadpool/config.rs index e92d2c607..cd34dbbb3 100644 --- a/tokio-threadpool/src/config.rs +++ b/tokio-executor/src/threadpool/config.rs @@ -1,4 +1,5 @@ -use crate::callback::Callback; +use super::callback::Callback; + use std::any::Any; use std::fmt; use std::sync::Arc; diff --git a/tokio-threadpool/src/lib.rs b/tokio-executor/src/threadpool/mod.rs similarity index 92% rename from tokio-threadpool/src/lib.rs rename to tokio-executor/src/threadpool/mod.rs index 0ce42b6c1..47b52a93d 100644 --- a/tokio-threadpool/src/lib.rs +++ b/tokio-executor/src/threadpool/mod.rs @@ -1,12 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/tokio-threadpool/0.2.0-alpha.1")] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] -#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] - //! A work-stealing based thread pool for executing futures. //! //! The Tokio thread pool supports scheduling futures and processing them on @@ -147,9 +138,9 @@ mod thread_pool; mod waker; mod worker; -pub use crate::blocking::{blocking, BlockingError}; -pub use crate::builder::Builder; -pub use crate::sender::Sender; -pub use crate::shutdown::Shutdown; -pub use crate::thread_pool::ThreadPool; -pub use crate::worker::{Worker, WorkerId}; +pub use self::blocking::{blocking, BlockingError}; +pub use self::builder::Builder; +pub use self::sender::Sender; +pub use self::shutdown::Shutdown; +pub use self::thread_pool::ThreadPool; +pub use self::worker::{Worker, WorkerId}; diff --git a/tokio-threadpool/src/park/boxed.rs b/tokio-executor/src/threadpool/park/boxed.rs similarity index 96% rename from tokio-threadpool/src/park/boxed.rs rename to tokio-executor/src/threadpool/park/boxed.rs index 6893c2f23..dae1820d2 100644 --- a/tokio-threadpool/src/park/boxed.rs +++ b/tokio-executor/src/threadpool/park/boxed.rs @@ -1,7 +1,8 @@ +use crate::park::{Park, Unpark}; + use log::warn; use std::error::Error; use std::time::Duration; -use tokio_executor::park::{Park, Unpark}; pub(crate) type BoxPark = Box + Send>; pub(crate) type BoxUnpark = Box; diff --git a/tokio-threadpool/src/park/default_park.rs b/tokio-executor/src/threadpool/park/default_park.rs similarity index 98% rename from tokio-threadpool/src/park/default_park.rs rename to tokio-executor/src/threadpool/park/default_park.rs index dd0713894..85c95cb7c 100644 --- a/tokio-threadpool/src/park/default_park.rs +++ b/tokio-executor/src/threadpool/park/default_park.rs @@ -1,8 +1,9 @@ +use crate::park::{Park, Unpark}; + use crossbeam_utils::sync::{Parker, Unparker}; use std::error::Error; use std::fmt; use std::time::Duration; -use tokio_executor::park::{Park, Unpark}; /// Parks the thread. #[derive(Debug)] diff --git a/tokio-threadpool/src/park/mod.rs b/tokio-executor/src/threadpool/park/mod.rs similarity index 100% rename from tokio-threadpool/src/park/mod.rs rename to tokio-executor/src/threadpool/park/mod.rs diff --git a/tokio-threadpool/src/pool/backup.rs b/tokio-executor/src/threadpool/pool/backup.rs similarity index 99% rename from tokio-threadpool/src/pool/backup.rs rename to tokio-executor/src/threadpool/pool/backup.rs index dc2aadea3..46ca3dadb 100644 --- a/tokio-threadpool/src/pool/backup.rs +++ b/tokio-executor/src/threadpool/pool/backup.rs @@ -1,5 +1,5 @@ -use crate::park::DefaultPark; -use crate::worker::WorkerId; +use super::super::park::DefaultPark; +use super::super::worker::WorkerId; use std::cell::UnsafeCell; use std::fmt; diff --git a/tokio-threadpool/src/pool/backup_stack.rs b/tokio-executor/src/threadpool/pool/backup_stack.rs similarity index 99% rename from tokio-threadpool/src/pool/backup_stack.rs rename to tokio-executor/src/threadpool/pool/backup_stack.rs index f63a0b130..b55112bd9 100644 --- a/tokio-threadpool/src/pool/backup_stack.rs +++ b/tokio-executor/src/threadpool/pool/backup_stack.rs @@ -1,4 +1,4 @@ -use crate::pool::{Backup, BackupId}; +use super::{Backup, BackupId}; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::{AcqRel, Acquire}; diff --git a/tokio-threadpool/src/pool/mod.rs b/tokio-executor/src/threadpool/pool/mod.rs similarity index 98% rename from tokio-threadpool/src/pool/mod.rs rename to tokio-executor/src/threadpool/pool/mod.rs index 7b347eea0..e3601f1cc 100644 --- a/tokio-threadpool/src/pool/mod.rs +++ b/tokio-executor/src/threadpool/pool/mod.rs @@ -8,14 +8,14 @@ pub(crate) use self::state::{Lifecycle, State, MAX_FUTURES}; use self::backup::Handoff; use self::backup_stack::BackupStack; +use super::config::Config; +use super::shutdown::ShutdownTrigger; +use super::task::{Blocking, Task}; +use super::worker::{self, Worker, WorkerId}; +use super::BlockingError; -use crate::config::Config; -use crate::shutdown::ShutdownTrigger; -use crate::task::{Blocking, Task}; -use crate::worker::{self, Worker, WorkerId}; use crossbeam_deque::Injector; use crossbeam_utils::CachePadded; - use lazy_static::lazy_static; use log::{debug, error, trace}; use std::cell::Cell; @@ -203,7 +203,7 @@ impl Pool { } pub(crate) fn terminate_sleeping_workers(&self) { - use crate::worker::Lifecycle::Signaled; + use super::worker::Lifecycle::Signaled; trace!(" -> shutting down workers"); // Wakeup all sleeping workers. They will wake up, see the state @@ -225,7 +225,7 @@ impl Pool { pub(crate) fn poll_blocking_capacity( &self, task: &Arc, - ) -> Poll> { + ) -> Poll> { self.blocking.poll_blocking_capacity(task) } @@ -399,7 +399,7 @@ impl Pool { pub(crate) fn signal_work(&self, pool: &Arc) { debug_assert_eq!(*self, **pool); - use crate::worker::Lifecycle::Signaled; + use super::worker::Lifecycle::Signaled; if let Some((idx, worker_state)) = self.sleep_stack.pop(&self.workers, Signaled, false) { let entry = &self.workers[idx]; diff --git a/tokio-threadpool/src/pool/state.rs b/tokio-executor/src/threadpool/pool/state.rs similarity index 100% rename from tokio-threadpool/src/pool/state.rs rename to tokio-executor/src/threadpool/pool/state.rs diff --git a/tokio-threadpool/src/sender.rs b/tokio-executor/src/threadpool/sender.rs similarity index 87% rename from tokio-threadpool/src/sender.rs rename to tokio-executor/src/threadpool/sender.rs index 30e10b048..c090dd7d7 100644 --- a/tokio-threadpool/src/sender.rs +++ b/tokio-executor/src/threadpool/sender.rs @@ -1,7 +1,7 @@ -use crate::pool::{self, Lifecycle, Pool, MAX_FUTURES}; -use crate::task::Task; +use super::pool::{self, Lifecycle, Pool, MAX_FUTURES}; +use super::task::Task; -use tokio_executor::{self, SpawnError}; +use crate::{Executor, SpawnError, TypedExecutor}; use log::trace; use std::future::Future; @@ -62,7 +62,7 @@ impl Sender { /// ```rust /// #![feature(async_await)] /// - /// use tokio_threadpool::ThreadPool; + /// use tokio_executor::threadpool::ThreadPool; /// /// // Create a thread pool with default configuration values /// let thread_pool = ThreadPool::new(); @@ -79,7 +79,7 @@ impl Sender { F: Future + Send + 'static, { let mut s = self; - tokio_executor::Executor::spawn(&mut s, Box::pin(future)) + Executor::spawn(&mut s, Box::pin(future)) } /// Logic to prepare for spawning @@ -121,10 +121,10 @@ impl Sender { } } -impl tokio_executor::Executor for Sender { - fn status(&self) -> Result<(), tokio_executor::SpawnError> { +impl Executor for Sender { + fn status(&self) -> Result<(), SpawnError> { let s = self; - tokio_executor::Executor::status(&s) + Executor::status(&s) } fn spawn( @@ -132,12 +132,12 @@ impl tokio_executor::Executor for Sender { future: Pin + Send>>, ) -> Result<(), SpawnError> { let mut s = &*self; - tokio_executor::Executor::spawn(&mut s, future) + Executor::spawn(&mut s, future) } } -impl tokio_executor::Executor for &Sender { - fn status(&self) -> Result<(), tokio_executor::SpawnError> { +impl Executor for &Sender { + fn status(&self) -> Result<(), SpawnError> { let state: pool::State = self.pool.state.load(Acquire).into(); if state.num_futures() == MAX_FUTURES { @@ -174,16 +174,16 @@ impl tokio_executor::Executor for &Sender { } } -impl tokio_executor::TypedExecutor for Sender +impl TypedExecutor for Sender where T: Future + Send + 'static, { - fn status(&self) -> Result<(), tokio_executor::SpawnError> { - tokio_executor::Executor::status(self) + fn status(&self) -> Result<(), SpawnError> { + Executor::status(self) } fn spawn(&mut self, future: T) -> Result<(), SpawnError> { - tokio_executor::Executor::spawn(self, Box::pin(future)) + Executor::spawn(self, Box::pin(future)) } } diff --git a/tokio-threadpool/src/shutdown.rs b/tokio-executor/src/threadpool/shutdown.rs similarity index 96% rename from tokio-threadpool/src/shutdown.rs rename to tokio-executor/src/threadpool/shutdown.rs index 237d3b030..39c08e601 100644 --- a/tokio-threadpool/src/shutdown.rs +++ b/tokio-executor/src/threadpool/shutdown.rs @@ -1,5 +1,5 @@ -use crate::task::Task; -use crate::worker; +use super::task::Task; +use super::worker; use tokio_sync::AtomicWaker; @@ -45,7 +45,7 @@ impl Shutdown { /// Wait for the shutdown to complete pub fn wait(self) { - let mut enter = tokio_executor::enter().unwrap(); + let mut enter = crate::enter().unwrap(); enter.block_on(self); } } diff --git a/tokio-threadpool/src/task/blocking.rs b/tokio-executor/src/threadpool/task/blocking.rs similarity index 99% rename from tokio-threadpool/src/task/blocking.rs rename to tokio-executor/src/threadpool/task/blocking.rs index 92d985b24..fe21e0d91 100644 --- a/tokio-threadpool/src/task/blocking.rs +++ b/tokio-executor/src/threadpool/task/blocking.rs @@ -1,5 +1,6 @@ -use crate::pool::Pool; -use crate::task::{BlockingState, Task}; +use super::super::pool::Pool; +use super::super::task::{BlockingState, Task}; +use crate::threadpool::BlockingError; use std::cell::UnsafeCell; use std::fmt; @@ -113,7 +114,7 @@ impl Blocking { pub(crate) fn poll_blocking_capacity( &self, task: &Arc, - ) -> Poll> { + ) -> Poll> { // This requires atomically claiming blocking capacity and if none is // available, queuing &task. diff --git a/tokio-threadpool/src/task/blocking_state.rs b/tokio-executor/src/threadpool/task/blocking_state.rs similarity index 98% rename from tokio-threadpool/src/task/blocking_state.rs rename to tokio-executor/src/threadpool/task/blocking_state.rs index db419fccb..8294f565c 100644 --- a/tokio-threadpool/src/task/blocking_state.rs +++ b/tokio-executor/src/threadpool/task/blocking_state.rs @@ -1,4 +1,5 @@ -use crate::task::CanBlock; +use super::CanBlock; + use std::fmt; use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/tokio-threadpool/src/task/mod.rs b/tokio-executor/src/threadpool/task/mod.rs similarity index 99% rename from tokio-threadpool/src/task/mod.rs rename to tokio-executor/src/threadpool/task/mod.rs index 2b7d5bff9..b4dc43396 100644 --- a/tokio-threadpool/src/task/mod.rs +++ b/tokio-executor/src/threadpool/task/mod.rs @@ -5,8 +5,8 @@ mod state; pub(crate) use self::blocking::{Blocking, CanBlock}; use self::blocking_state::BlockingState; use self::state::State; -use crate::pool::Pool; -use crate::waker::Waker; +use super::pool::Pool; +use super::waker::Waker; use futures_util::task; use log::trace; diff --git a/tokio-threadpool/src/task/state.rs b/tokio-executor/src/threadpool/task/state.rs similarity index 100% rename from tokio-threadpool/src/task/state.rs rename to tokio-executor/src/threadpool/task/state.rs diff --git a/tokio-threadpool/src/thread_pool.rs b/tokio-executor/src/threadpool/thread_pool.rs similarity index 95% rename from tokio-threadpool/src/thread_pool.rs rename to tokio-executor/src/threadpool/thread_pool.rs index 6c6a574fc..11ddb8aea 100644 --- a/tokio-threadpool/src/thread_pool.rs +++ b/tokio-executor/src/threadpool/thread_pool.rs @@ -1,7 +1,7 @@ -use crate::builder::Builder; -use crate::pool::Pool; -use crate::sender::Sender; -use crate::shutdown::{Shutdown, ShutdownTrigger}; +use super::builder::Builder; +use super::pool::Pool; +use super::sender::Sender; +use super::shutdown::{Shutdown, ShutdownTrigger}; use std::future::Future; use std::sync::Arc; @@ -53,7 +53,7 @@ impl ThreadPool { /// ```rust /// #![feature(async_await)] /// - /// use tokio_threadpool::ThreadPool; + /// use tokio_executor::threadpool::ThreadPool; /// /// // Create a thread pool with default configuration values /// let thread_pool = ThreadPool::new(); @@ -90,7 +90,7 @@ impl ThreadPool { /// # Examples /// /// ```rust - /// # use tokio_threadpool::ThreadPool; + /// # use tokio_executor::threadpool::ThreadPool; /// use futures::future::{Future, lazy}; /// /// // Create a thread pool with default configuration values @@ -188,7 +188,7 @@ impl Drop for ThreadPool { drop(inner); // Wait until all worker threads terminate and the threadpool's resources clean up. - let mut enter = match tokio_executor::enter() { + let mut enter = match crate::enter() { Ok(e) => e, Err(_) => return, }; diff --git a/tokio-threadpool/src/waker.rs b/tokio-executor/src/threadpool/waker.rs similarity index 91% rename from tokio-threadpool/src/waker.rs rename to tokio-executor/src/threadpool/waker.rs index b1fd97d4c..454cbda4d 100644 --- a/tokio-threadpool/src/waker.rs +++ b/tokio-executor/src/threadpool/waker.rs @@ -1,5 +1,5 @@ -use crate::pool::Pool; -use crate::task::Task; +use super::pool::Pool; +use super::task::Task; use futures_util::task::ArcWake; use std::sync::Arc; diff --git a/tokio-threadpool/src/worker/entry.rs b/tokio-executor/src/threadpool/worker/entry.rs similarity index 98% rename from tokio-threadpool/src/worker/entry.rs rename to tokio-executor/src/threadpool/worker/entry.rs index 66ae1d670..03c3b21d3 100644 --- a/tokio-threadpool/src/worker/entry.rs +++ b/tokio-executor/src/threadpool/worker/entry.rs @@ -1,6 +1,7 @@ -use crate::park::{BoxPark, BoxUnpark}; -use crate::task::Task; -use crate::worker::state::{State, PUSHED_MASK}; +use super::super::park::{BoxPark, BoxUnpark}; +use super::super::task::Task; +use super::state::{State, PUSHED_MASK}; + use crossbeam_deque::{Steal, Stealer, Worker}; use crossbeam_queue::SegQueue; use crossbeam_utils::CachePadded; @@ -94,7 +95,7 @@ impl WorkerEntry { /// The `state` must have been obtained with an `Acquire` ordering. #[inline] pub(crate) fn notify(&self, mut state: State) -> bool { - use crate::worker::Lifecycle::*; + use super::Lifecycle::*; loop { let mut next = state; @@ -139,7 +140,7 @@ impl WorkerEntry { /// /// Returns `Err` if the worker has already terminated. pub(crate) fn signal_stop(&self, mut state: State) { - use crate::worker::Lifecycle::*; + use super::Lifecycle::*; // Transition the worker state to signaled loop { diff --git a/tokio-threadpool/src/worker/mod.rs b/tokio-executor/src/threadpool/worker/mod.rs similarity index 98% rename from tokio-threadpool/src/worker/mod.rs rename to tokio-executor/src/threadpool/worker/mod.rs index 3bd006bb6..0ffb5ef54 100644 --- a/tokio-threadpool/src/worker/mod.rs +++ b/tokio-executor/src/threadpool/worker/mod.rs @@ -6,12 +6,11 @@ pub(crate) use self::entry::WorkerEntry as Entry; pub(crate) use self::stack::Stack; pub(crate) use self::state::{Lifecycle, State}; -use crate::pool::{self, BackupId, Pool}; -use crate::sender::Sender; -use crate::shutdown::ShutdownTrigger; -use crate::task::{self, CanBlock, Task}; - -use tokio_executor; +use super::pool::{self, BackupId, Pool}; +use super::sender::Sender; +use super::shutdown::ShutdownTrigger; +use super::task::{self, CanBlock, Task}; +use super::BlockingError; use log::trace; use std::cell::Cell; @@ -120,9 +119,9 @@ impl Worker { let mut sender = Sender { pool }; // Enter an execution context - let _enter = tokio_executor::enter().unwrap(); + let _enter = crate::enter().unwrap(); - tokio_executor::with_default(&mut sender, || { + crate::with_default(&mut sender, || { if let Some(ref callback) = self.pool.config.around_worker { callback.call(self); } else { @@ -150,7 +149,7 @@ impl Worker { } /// Transition the current worker to a blocking worker - pub(crate) fn transition_to_blocking(&self) -> Poll> { + pub(crate) fn transition_to_blocking(&self) -> Poll> { use self::CanBlock::*; // If we get this far, then `current_task` has been set. @@ -442,7 +441,7 @@ impl Worker { } fn run_task(&self, task: Arc, pool: &Arc) { - use crate::task::Run::*; + use super::task::Run::*; // If this is the first time this task is being polled, register it so that we can keep // track of tasks that are in progress. diff --git a/tokio-threadpool/src/worker/stack.rs b/tokio-executor/src/threadpool/worker/stack.rs similarity index 99% rename from tokio-threadpool/src/worker/stack.rs rename to tokio-executor/src/threadpool/worker/stack.rs index 47c9cdbab..2559fb68e 100644 --- a/tokio-threadpool/src/worker/stack.rs +++ b/tokio-executor/src/threadpool/worker/stack.rs @@ -1,5 +1,6 @@ -use crate::config::MAX_WORKERS; -use crate::worker; +use super::super::config::MAX_WORKERS; +use super::super::worker; + use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed}; use std::{fmt, usize}; diff --git a/tokio-threadpool/src/worker/state.rs b/tokio-executor/src/threadpool/worker/state.rs similarity index 100% rename from tokio-threadpool/src/worker/state.rs rename to tokio-executor/src/threadpool/worker/state.rs diff --git a/tokio-threadpool/tests/threadpool.rs b/tokio-executor/tests/threadpool.rs similarity index 97% rename from tokio-threadpool/tests/threadpool.rs rename to tokio-executor/tests/threadpool.rs index cf3af15c5..4021fcad2 100644 --- a/tokio-threadpool/tests/threadpool.rs +++ b/tokio-executor/tests/threadpool.rs @@ -2,9 +2,10 @@ #![feature(async_await)] use tokio_executor::park::{Park, Unpark}; +use tokio_executor::threadpool; +use tokio_executor::threadpool::park::{DefaultPark, DefaultUnpark}; +use tokio_executor::threadpool::*; use tokio_test::assert_pending; -use tokio_threadpool::park::{DefaultPark, DefaultUnpark}; -use tokio_threadpool::*; use std::cell::Cell; use std::future::Future; @@ -19,8 +20,6 @@ thread_local!(static FOO: Cell = Cell::new(0)); #[test] fn natural_shutdown_simple_futures() { - let _ = ::env_logger::try_init(); - for _ in 0..1_000 { let num_inc = Arc::new(AtomicUsize::new(0)); let num_dec = Arc::new(AtomicUsize::new(0)); @@ -88,8 +87,6 @@ fn natural_shutdown_simple_futures() { #[test] fn force_shutdown_drops_futures() { - let _ = ::env_logger::try_init(); - for _ in 0..1_000 { let num_inc = Arc::new(AtomicUsize::new(0)); let num_dec = Arc::new(AtomicUsize::new(0)); @@ -144,8 +141,6 @@ fn force_shutdown_drops_futures() { #[test] fn drop_threadpool_drops_futures() { - let _ = ::env_logger::try_init(); - for _ in 0..1_000 { let num_inc = Arc::new(AtomicUsize::new(0)); let num_dec = Arc::new(AtomicUsize::new(0)); @@ -204,8 +199,6 @@ fn drop_threadpool_drops_futures() { fn many_oneshot_futures() { const NUM: usize = 10_000; - let _ = ::env_logger::try_init(); - for _ in 0..50 { let pool = ThreadPool::new(); let tx = pool.sender().clone(); @@ -235,8 +228,6 @@ fn many_multishot_futures() { const CYCLES: usize = 5; const TRACKS: usize = 50; - let _ = ::env_logger::try_init(); - for _ in 0..50 { let pool = ThreadPool::new(); let pool_tx = pool.sender().clone(); @@ -398,7 +389,7 @@ fn panic_in_task() { fn count_panics() { let counter = Arc::new(AtomicUsize::new(0)); let counter_ = counter.clone(); - let pool = tokio_threadpool::Builder::new() + let pool = threadpool::Builder::new() .panic_handler(move |_err| { // We caught a panic. counter_.fetch_add(1, Relaxed); @@ -481,7 +472,7 @@ fn eagerly_drops_futures() { let (park_tx, park_rx) = mpsc::sync_channel(0); let (unpark_tx, unpark_rx) = mpsc::sync_channel(0); - let pool = tokio_threadpool::Builder::new() + let pool = threadpool::Builder::new() .custom_park(move |_| MyPark { inner: DefaultPark::new(), park_tx: park_tx.clone(), diff --git a/tokio-threadpool/tests/blocking.rs b/tokio-executor/tests/threadpool_blocking.rs similarity index 99% rename from tokio-threadpool/tests/blocking.rs rename to tokio-executor/tests/threadpool_blocking.rs index b2c48493d..8c133b50d 100644 --- a/tokio-threadpool/tests/blocking.rs +++ b/tokio-executor/tests/threadpool_blocking.rs @@ -1,8 +1,8 @@ #![warn(rust_2018_idioms)] #![feature(async_await)] +use tokio_executor::threadpool::*; use tokio_test::*; -use tokio_threadpool::*; use futures_core::ready; use futures_util::future::poll_fn; @@ -16,8 +16,6 @@ use std::time::Duration; #[test] fn basic() { - let _ = ::env_logger::try_init(); - let pool = Builder::new().pool_size(1).max_blocking(1).build(); let (tx1, rx1) = mpsc::channel(); @@ -41,8 +39,6 @@ fn basic() { #[test] fn other_executors_can_run_inside_blocking() { - let _ = ::env_logger::try_init(); - let pool = Builder::new().pool_size(1).max_blocking(1).build(); let (tx, rx) = mpsc::channel(); diff --git a/tokio-threadpool/tests/hammer.rs b/tokio-executor/tests/threadpool_hammer.rs similarity index 98% rename from tokio-threadpool/tests/hammer.rs rename to tokio-executor/tests/threadpool_hammer.rs index 3bb9af84a..20a9e0ab2 100644 --- a/tokio-threadpool/tests/hammer.rs +++ b/tokio-executor/tests/threadpool_hammer.rs @@ -1,8 +1,8 @@ #![warn(rust_2018_idioms)] #![feature(async_await)] +use tokio_executor::threadpool::*; use tokio_sync::{mpsc, oneshot}; -use tokio_threadpool::*; use std::future::Future; use std::pin::Pin; diff --git a/tokio-fs/Cargo.toml b/tokio-fs/Cargo.toml index 91cd1058d..59db2fa81 100644 --- a/tokio-fs/Cargo.toml +++ b/tokio-fs/Cargo.toml @@ -23,7 +23,7 @@ categories = ["asynchronous", "network-programming", "filesystem"] [dependencies] tokio-io = { version = "=0.2.0-alpha.1", features = ["util"], path = "../tokio-io" } -tokio-threadpool = { version = "=0.2.0-alpha.1", path = "../tokio-threadpool" } +tokio-executor = { version = "=0.2.0-alpha.1", features = ["threadpool"], path = "../tokio-executor" } futures-core-preview = "=0.3.0-alpha.18" futures-util-preview = "=0.3.0-alpha.18" diff --git a/tokio-fs/src/lib.rs b/tokio-fs/src/lib.rs index 341502dc7..4cb6fee58 100644 --- a/tokio-fs/src/lib.rs +++ b/tokio-fs/src/lib.rs @@ -28,12 +28,12 @@ //! 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-threadpool] for more details +//! to a *backup* thread immediately. See [tokio-executor] for more details //! of the threading model and [`blocking`]. //! -//! [`blocking`]: https://docs.rs/tokio-threadpool/0.1/tokio_threadpool/fn.blocking.html +//! [`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-threadpool]: https://docs.rs/tokio-threadpool/0.1/tokio_threadpool +//! [tokio-executor]: https://docs.rs/tokio-executor/0.2.0-alpha.2/tokio_executor/threadpool/index.html mod create_dir; mod create_dir_all; @@ -85,7 +85,9 @@ fn blocking_io(f: F) -> Poll> where F: FnOnce() -> io::Result, { - match tokio_threadpool::blocking(f) { + use tokio_executor::threadpool::blocking; + + match blocking(f) { Ready(Ok(v)) => Ready(v), Ready(Err(_)) => Ready(Err(blocking_err())), Pending => Pending, diff --git a/tokio-fs/tests/pool/mod.rs b/tokio-fs/tests/pool/mod.rs index 9cce3b036..39eab7d18 100644 --- a/tokio-fs/tests/pool/mod.rs +++ b/tokio-fs/tests/pool/mod.rs @@ -1,6 +1,5 @@ -use tokio_threadpool; +use tokio_executor::threadpool::Builder; -use self::tokio_threadpool::Builder; use std::future::Future; use std::io; use std::sync::mpsc; diff --git a/tokio-threadpool/CHANGELOG.md b/tokio-threadpool/CHANGELOG.md deleted file mode 100644 index c399db7c3..000000000 --- a/tokio-threadpool/CHANGELOG.md +++ /dev/null @@ -1,85 +0,0 @@ -# 0.2.0-alpha.1 (August 8, 2019) - -### Changed -- Switch to `async`, `await`, and `std::future`. - -# 0.1.14 (April 22, 2019) - -### Added -- Add `panic_handler` for customizing action taken on panic (#1052). - -# 0.1.13 (March 22, 2019) - -### Added -- `TypedExecutor` implementations (#993) - -# 0.1.12 (March 1, 2019) - -### Fixed -- Documentation typos (#915). - -### Changed -- Update crossbeam dependencies (#874). - -# 0.1.11 (January 24, 2019) - -### Fixed -- Drop incomplete tasks when threadpool is dropped (#722). - -# 0.1.10 (January 6, 2019) - -* Fix deadlock bug in `blocking` (#795). -* Introduce global task queue (#798). -* Use crossbeam's Parker / Unparker (#529). -* Panic if worker thread cannot be spawned (#826). -* Improve `blocking` API documentation (#789). - -# 0.1.9 (November 21, 2018) - -* Bump internal dependency versions (#746, #753). -* Internal refactors (#768, #769). - -# 0.1.8 (October 23, 2018) - -* Assign spawned tasks to random worker (#660). -* Worker threads no longer shutdown (#692). -* Reduce atomic ops in notifier (#702). - -# 0.1.7 (September 27, 2018) - -* Add ThreadPool::spawn_handle (#602, #604). -* Fix spawned future leak (#649). - -# 0.1.6 (August 23, 2018) - -* Misc performance improvements (#466, #468, #470, #475, #534) -* Documentation improvements (#450) -* Shutdown backup threads when idle (#489) -* Implement std::error::Error for error types (#511) -* Bugfix: handle num_cpus returning zero (#530). - -# 0.1.5 (July 3, 2018) - -* Fix race condition bug when threads are woken up (#459). -* Improve `BlockingError` message (#451). - -# 0.1.4 (June 6, 2018) - -* Fix bug that can occur with multiple pools in a process (#375). - -# 0.1.3 (May 2, 2018) - -* Add `blocking` annotation (#317). - -# 0.1.2 (March 30, 2018) - -* Add the ability to specify a custom thread parker. - -# 0.1.1 (March 22, 2018) - -* Handle futures that panic on the threadpool. -* Optionally support futures 0.2. - -# 0.1.0 (March 09, 2018) - -* Initial release diff --git a/tokio-threadpool/Cargo.toml b/tokio-threadpool/Cargo.toml deleted file mode 100644 index 740fc30e0..000000000 --- a/tokio-threadpool/Cargo.toml +++ /dev/null @@ -1,43 +0,0 @@ -[package] -name = "tokio-threadpool" -# When releasing to crates.io: -# - Remove path dependencies -# - Update html_root_url. -# - Update doc url -# - Cargo.toml -# - README.md -# - Update CHANGELOG.md. -# - Create "v0.2.x" git tag. -version = "0.2.0-alpha.1" -edition = "2018" -documentation = "https://docs.rs/tokio-threadpool/0.2.0-alpha.1/tokio_threadpool" -repository = "https://github.com/tokio-rs/tokio" -homepage = "https://github.com/tokio-rs/tokio" -license = "MIT" -authors = ["Tokio Contributors "] -description = """ -A task scheduler backed by a work-stealing thread pool. -""" -keywords = ["futures", "tokio"] -categories = ["concurrency", "asynchronous"] - -[dependencies] -tokio-executor = { version = "=0.2.0-alpha.1", path = "../tokio-executor" } -tokio-sync = { version = "=0.2.0-alpha.1", path = "../tokio-sync" } -futures-core-preview = "=0.3.0-alpha.18" -futures-util-preview = "=0.3.0-alpha.18" - -crossbeam-deque = "0.7.0" -crossbeam-queue = "0.1.0" -crossbeam-utils = "0.6.4" -num_cpus = "1.2" -slab = "0.4.1" -log = "0.4" -lazy_static = "1" - -[dev-dependencies] -tokio = { version = "=0.2.0-alpha.1", path = "../tokio" } -tokio-test = { version = "=0.2.0-alpha.1", path = "../tokio-test" } - -rand = "0.7" -env_logger = { version = "0.6", default-features = false } diff --git a/tokio-threadpool/LICENSE b/tokio-threadpool/LICENSE deleted file mode 100644 index cdb28b4b5..000000000 --- a/tokio-threadpool/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-threadpool/README.md b/tokio-threadpool/README.md deleted file mode 100644 index 31f658a1f..000000000 --- a/tokio-threadpool/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Tokio Thread Pool - -A library for scheduling execution of futures concurrently across a pool of -threads. - -## 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/Cargo.toml b/tokio/Cargo.toml index efed28ed0..815346b63 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -44,8 +44,8 @@ rt-full = [ "sync", "timer", "tokio-executor/current-thread", + "tokio-executor/threadpool", "tokio-macros", - "tokio-threadpool", "tracing-core", ] sync = ["tokio-sync"] @@ -69,7 +69,6 @@ tokio-executor = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio tokio-macros = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-macros" } tokio-net = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-net" } tokio-sync = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-sync", features = ["async-traits"] } -tokio-threadpool = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-threadpool" } tokio-tcp = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-tcp", features = ["async-traits"] } tokio-udp = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-udp" } tokio-timer = { version = "=0.3.0-alpha.1", optional = true, path = "../tokio-timer", features = ["async-traits"] } diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index a6ce79916..ac17461d7 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -133,7 +133,7 @@ //! [timer]: ../timer/index.html //! [`Runtime`]: struct.Runtime.html //! [`Reactor`]: ../reactor/struct.Reactor.html -//! [`ThreadPool`]: https://docs.rs/tokio-threadpool/0.1/tokio_threadpool/struct.ThreadPool.html +//! [`ThreadPool`]: https://docs.rs/tokio-executor/0.2.0-alpha.2/tokio_executor/threadpool/struct.ThreadPool.html //! [`run`]: fn.run.html //! [idle]: struct.Runtime.html#method.shutdown_on_idle //! [`tokio::spawn`]: ../executor/fn.spawn.html diff --git a/tokio/src/runtime/threadpool/builder.rs b/tokio/src/runtime/threadpool/builder.rs index d1586db6c..10beff32e 100644 --- a/tokio/src/runtime/threadpool/builder.rs +++ b/tokio/src/runtime/threadpool/builder.rs @@ -1,7 +1,7 @@ use super::{background, Inner, Runtime}; use crate::reactor::Reactor; -use tokio_threadpool::Builder as ThreadPoolBuilder; +use tokio_executor::threadpool; use tokio_timer::clock::{self, Clock}; use tokio_timer::timer::{self, Timer}; @@ -51,7 +51,7 @@ use std::any::Any; #[derive(Debug)] pub struct Builder { /// Thread pool specific builder - threadpool_builder: ThreadPoolBuilder, + threadpool_builder: threadpool::Builder, /// The number of worker threads core_threads: usize, @@ -68,7 +68,7 @@ impl Builder { pub fn new() -> Builder { let core_threads = num_cpus::get().max(1); - let mut threadpool_builder = ThreadPoolBuilder::new(); + let mut threadpool_builder = threadpool::Builder::new(); threadpool_builder.name_prefix("tokio-runtime-worker-"); threadpool_builder.pool_size(core_threads); diff --git a/tokio/src/runtime/threadpool/mod.rs b/tokio/src/runtime/threadpool/mod.rs index ca4f892af..19bcdf07d 100644 --- a/tokio/src/runtime/threadpool/mod.rs +++ b/tokio/src/runtime/threadpool/mod.rs @@ -9,6 +9,7 @@ pub use self::task_executor::TaskExecutor; use background::Background; use tokio_executor::enter; +use tokio_executor::threadpool::ThreadPool; use tokio_timer::timer; use tracing_core as trace; @@ -37,7 +38,7 @@ pub struct Runtime { #[derive(Debug)] struct Inner { /// Task execution pool. - pool: tokio_threadpool::ThreadPool, + pool: ThreadPool, /// Tracing dispatcher trace: trace::Dispatch, diff --git a/tokio/src/runtime/threadpool/task_executor.rs b/tokio/src/runtime/threadpool/task_executor.rs index 9dee3fcbc..5ecfb7ccf 100644 --- a/tokio/src/runtime/threadpool/task_executor.rs +++ b/tokio/src/runtime/threadpool/task_executor.rs @@ -1,5 +1,5 @@ use tokio_executor::SpawnError; -use tokio_threadpool::Sender; +use tokio_executor::threadpool::Sender; use std::future::Future; use std::pin::Pin;