diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-18 07:00:55 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-18 07:00:55 -0800 |
commit | 0d38936b35779b604770120da2e98560bbb6241f (patch) | |
tree | 843d46e999becdb580cb02655b4290acadd64474 /tokio/src/runtime/thread_pool | |
parent | 13b6e9939e062dc01bcf34abe3d75de4b66e20e1 (diff) |
chore: refine feature flags (#1785)
Removes dependencies between Tokio feature flags. For example, `process`
should not depend on `sync` simply because it uses the `mpsc` channel.
Instead, feature flags represent **public** APIs that become available
with the feature enabled. When the feature is not enabled, the
functionality is removed. If another Tokio component requires the
functionality, it is stays as `pub(crate)`.
The threaded scheduler is now exposed under `rt-threaded`. This feature
flag only enables the threaded scheduler and does not include I/O,
networking, or time. Those features must be explictly enabled.
A `full` feature flag is added that enables all features.
`stdin`, `stdout`, `stderr` are exposed under `io-std`.
Macros are used to scope code by feature flag.
Diffstat (limited to 'tokio/src/runtime/thread_pool')
-rw-r--r-- | tokio/src/runtime/thread_pool/mod.rs | 4 | ||||
-rw-r--r-- | tokio/src/runtime/thread_pool/worker.rs | 38 |
2 files changed, 23 insertions, 19 deletions
diff --git a/tokio/src/runtime/thread_pool/mod.rs b/tokio/src/runtime/thread_pool/mod.rs index b45d3707..4b23c3b9 100644 --- a/tokio/src/runtime/thread_pool/mod.rs +++ b/tokio/src/runtime/thread_pool/mod.rs @@ -22,7 +22,9 @@ mod shutdown; mod worker; -pub(crate) use worker::block_in_place; +cfg_blocking! { + pub(crate) use worker::block_in_place; +} /// Unit tests #[cfg(test)] diff --git a/tokio/src/runtime/thread_pool/worker.rs b/tokio/src/runtime/thread_pool/worker.rs index 2de2101e..cf6b66d8 100644 --- a/tokio/src/runtime/thread_pool/worker.rs +++ b/tokio/src/runtime/thread_pool/worker.rs @@ -15,24 +15,26 @@ thread_local! { static ON_BLOCK: Cell<Option<*const dyn Fn()>> = Cell::new(None) } -pub(crate) fn block_in_place<F, R>(f: F) -> R -where - F: FnOnce() -> R, -{ - // Make the current worker give away its Worker to another thread so that we can safely block - // this one without preventing progress on other futures the worker owns. - ON_BLOCK.with(|ob| { - let allow_blocking = ob - .get() - .expect("can only call blocking when on Tokio runtime"); - - // This is safe, because ON_BLOCK was set from an &mut dyn FnMut in the worker that wraps - // the worker's operation, and is unset just prior to when the FnMut is dropped. - let allow_blocking = unsafe { &*allow_blocking }; - - allow_blocking(); - f() - }) +cfg_blocking! { + pub(crate) fn block_in_place<F, R>(f: F) -> R + where + F: FnOnce() -> R, + { + // Make the current worker give away its Worker to another thread so that we can safely block + // this one without preventing progress on other futures the worker owns. + ON_BLOCK.with(|ob| { + let allow_blocking = ob + .get() + .expect("can only call blocking when on Tokio runtime"); + + // This is safe, because ON_BLOCK was set from an &mut dyn FnMut in the worker that wraps + // the worker's operation, and is unset just prior to when the FnMut is dropped. + let allow_blocking = unsafe { &*allow_blocking }; + + allow_blocking(); + f() + }) + } } pub(crate) struct Worker<P: Park + 'static> { |