From 8546ff826db8dba1e39b4119ad909fb6cab2492a Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 21 Nov 2019 23:28:39 -0800 Subject: runtime: cleanup and add config options (#1807) * runtime: cleanup and add config options This patch finishes the cleanup as part of the transition to Tokio 0.2. A number of changes were made to take advantage of having all Tokio types in a single crate. Also, fixes using Tokio types from `spawn_blocking`. * Many threads, one resource driver Previously, in the threaded scheduler, a resource driver (mio::Poll / timer combo) was created per thread. This was more or less fine, except it required balancing across the available drivers. When using a resource driver from **outside** of the thread pool, balancing is tricky. The change was original done to avoid having a dedicated driver thread. Now, instead of creating many resource drivers, a single resource driver is used. Each scheduler thread will attempt to "lock" the resource driver before parking on it. If the resource driver is already locked, the thread uses a condition variable to park. Contention should remain low as, under load, the scheduler avoids using the drivers. * Add configuration options to enable I/O / time New configuration options are added to `runtime::Builder` to allow enabling I/O and time drivers on a runtime instance basis. This is useful when wanting to create lightweight runtime instances to execute compute only tasks. * Bug fixes The condition variable parker is updated to the same algorithm used in `std`. This is motivated by some potential deadlock cases discovered by `loom`. The basic scheduler is fixed to fairly schedule tasks. `push_front` was accidentally used instead of `push_back`. I/O, time, and spawning now work from within `spawn_blocking` closures. * Misc cleanup The threaded scheduler is no longer generic over `P :Park`. Instead, it is hard coded to a specific parker. Tests, including loom tests, are updated to use `Runtime` directly. This provides greater coverage. The `blocking` module is moved back into `runtime` as all usage is within `runtime` itself. --- tokio-test/src/io.rs | 2 ++ tokio-test/src/lib.rs | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'tokio-test') diff --git a/tokio-test/src/io.rs b/tokio-test/src/io.rs index 5a2b74bf..e6a243a1 100644 --- a/tokio-test/src/io.rs +++ b/tokio-test/src/io.rs @@ -1,3 +1,5 @@ +#![cfg(not(loom))] + //! A mock type implementing [`AsyncRead`] and [`AsyncWrite`]. //! //! diff --git a/tokio-test/src/lib.rs b/tokio-test/src/lib.rs index bdd4a9f9..d70a0c22 100644 --- a/tokio-test/src/lib.rs +++ b/tokio-test/src/lib.rs @@ -14,6 +14,7 @@ //! Tokio and Futures based testing utilites pub mod io; + mod macros; pub mod task; @@ -27,7 +28,11 @@ pub mod task; pub fn block_on(future: F) -> F::Output { use tokio::runtime; - let mut rt = runtime::Builder::new().basic_scheduler().build().unwrap(); + let mut rt = runtime::Builder::new() + .basic_scheduler() + .enable_all() + .build() + .unwrap(); rt.block_on(future) } -- cgit v1.2.3