summaryrefslogtreecommitdiffstats
path: root/tokio/src/park/thread.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/park/thread.rs')
-rw-r--r--tokio/src/park/thread.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/tokio/src/park/thread.rs b/tokio/src/park/thread.rs
index 59513e1d..853d4d8a 100644
--- a/tokio/src/park/thread.rs
+++ b/tokio/src/park/thread.rs
@@ -230,12 +230,17 @@ cfg_blocking_impl! {
}
}
+ pub(crate) fn get_unpark(&self) -> Result<UnparkThread, ParkError> {
+ self.with_current(|park_thread| park_thread.unpark())
+ }
+
/// Get a reference to the `ParkThread` handle for this thread.
- fn with_current<F, R>(&self, f: F) -> R
+ fn with_current<F, R>(&self, f: F) -> Result<R, ParkError>
where
F: FnOnce(&ParkThread) -> R,
{
- CURRENT_PARKER.with(|inner| f(inner))
+ CURRENT_PARKER.try_with(|inner| f(inner))
+ .map_err(|_| ParkError { _p: () })
}
}
@@ -244,16 +249,16 @@ cfg_blocking_impl! {
type Error = ParkError;
fn unpark(&self) -> Self::Unpark {
- self.with_current(|park_thread| park_thread.unpark())
+ self.get_unpark().unwrap()
}
fn park(&mut self) -> Result<(), Self::Error> {
- self.with_current(|park_thread| park_thread.inner.park());
+ self.with_current(|park_thread| park_thread.inner.park())?;
Ok(())
}
fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error> {
- self.with_current(|park_thread| park_thread.inner.park_timeout(duration));
+ self.with_current(|park_thread| park_thread.inner.park_timeout(duration))?;
Ok(())
}
}