diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-21 23:28:39 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-21 23:28:39 -0800 |
commit | 8546ff826db8dba1e39b4119ad909fb6cab2492a (patch) | |
tree | 0c1cdd36aaf9d732079a4ff7a71e5c6b138e7d42 /tokio/src/runtime/tests | |
parent | 6866fe426cfab0e4da3e88c673f7bef141259bb6 (diff) |
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.
Diffstat (limited to 'tokio/src/runtime/tests')
-rw-r--r-- | tokio/src/runtime/tests/mock_park.rs | 66 | ||||
-rw-r--r-- | tokio/src/runtime/tests/mod.rs | 3 |
2 files changed, 0 insertions, 69 deletions
diff --git a/tokio/src/runtime/tests/mock_park.rs b/tokio/src/runtime/tests/mock_park.rs deleted file mode 100644 index 0fe28b36..00000000 --- a/tokio/src/runtime/tests/mock_park.rs +++ /dev/null @@ -1,66 +0,0 @@ -#![allow(warnings)] - -use crate::runtime::{Park, Unpark}; - -use std::collections::HashMap; -use std::sync::atomic::{AtomicBool, Ordering::SeqCst}; -use std::sync::Arc; -use std::time::Duration; - -pub struct MockPark { - parks: HashMap<usize, Arc<Inner>>, -} - -#[derive(Clone)] -struct ParkImpl(Arc<Inner>); - -struct Inner { - unparked: AtomicBool, -} - -impl MockPark { - pub fn new() -> MockPark { - MockPark { - parks: HashMap::new(), - } - } - - pub fn is_unparked(&self, index: usize) -> bool { - self.parks[&index].unparked.load(SeqCst) - } - - pub fn clear(&self, index: usize) { - self.parks[&index].unparked.store(false, SeqCst); - } - - pub fn mk_park(&mut self, index: usize) -> impl Park { - let inner = Arc::new(Inner { - unparked: AtomicBool::new(false), - }); - self.parks.insert(index, inner.clone()); - ParkImpl(inner) - } -} - -impl Park for ParkImpl { - type Unpark = ParkImpl; - type Error = (); - - fn unpark(&self) -> Self::Unpark { - self.clone() - } - - fn park(&mut self) -> Result<(), Self::Error> { - unimplemented!(); - } - - fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error> { - unimplemented!(); - } -} - -impl Unpark for ParkImpl { - fn unpark(&self) { - self.0.unparked.store(true, SeqCst); - } -} diff --git a/tokio/src/runtime/tests/mod.rs b/tokio/src/runtime/tests/mod.rs index 99ed8cd8..a1910a44 100644 --- a/tokio/src/runtime/tests/mod.rs +++ b/tokio/src/runtime/tests/mod.rs @@ -2,6 +2,3 @@ #[cfg(loom)] pub(crate) mod loom_oneshot; - -#[cfg(not(loom))] -pub(crate) mod mock_park; |