summaryrefslogtreecommitdiffstats
path: root/tokio/src/runtime/thread_pool/worker.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/runtime/thread_pool/worker.rs')
-rw-r--r--tokio/src/runtime/thread_pool/worker.rs38
1 files changed, 20 insertions, 18 deletions
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> {