aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/context.rs
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2020-10-23 09:39:31 -0700
committerJoel Galenson <jgalenson@google.com>2020-10-23 09:52:09 -0700
commitd5495b03381a3ebe0805db353d198b285b535b5c (patch)
tree778b8524d15fca8b73db0253ee0e1919d0848bb6 /src/runtime/context.rs
parentba45c5bedf31df8562364c61d3dfb5262f10642e (diff)
downloadtokio-d5495b03381a3ebe0805db353d198b285b535b5c.tar.gz
Update to tokio-0.3.1 and add new features
Test: Build Change-Id: I5b5b9b386a21982a019653d0cf0bd3afc505cfac
Diffstat (limited to 'src/runtime/context.rs')
-rw-r--r--src/runtime/context.rs50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/runtime/context.rs b/src/runtime/context.rs
index 1b267f4..0817019 100644
--- a/src/runtime/context.rs
+++ b/src/runtime/context.rs
@@ -12,7 +12,7 @@ pub(crate) fn current() -> Option<Handle> {
}
cfg_io_driver! {
- pub(crate) fn io_handle() -> crate::runtime::io::Handle {
+ pub(crate) fn io_handle() -> crate::runtime::driver::IoHandle {
CONTEXT.with(|ctx| match *ctx.borrow() {
Some(ref ctx) => ctx.io_handle.clone(),
None => Default::default(),
@@ -20,8 +20,18 @@ cfg_io_driver! {
}
}
+cfg_signal_internal! {
+ #[cfg(unix)]
+ pub(crate) fn signal_handle() -> crate::runtime::driver::SignalHandle {
+ CONTEXT.with(|ctx| match *ctx.borrow() {
+ Some(ref ctx) => ctx.signal_handle.clone(),
+ None => Default::default(),
+ })
+ }
+}
+
cfg_time! {
- pub(crate) fn time_handle() -> crate::runtime::time::Handle {
+ pub(crate) fn time_handle() -> crate::runtime::driver::TimeHandle {
CONTEXT.with(|ctx| match *ctx.borrow() {
Some(ref ctx) => ctx.time_handle.clone(),
None => Default::default(),
@@ -29,7 +39,7 @@ cfg_time! {
}
cfg_test_util! {
- pub(crate) fn clock() -> Option<crate::runtime::time::Clock> {
+ pub(crate) fn clock() -> Option<crate::runtime::driver::Clock> {
CONTEXT.with(|ctx| match *ctx.borrow() {
Some(ref ctx) => Some(ctx.clock.clone()),
None => None,
@@ -38,7 +48,7 @@ cfg_time! {
}
}
-cfg_rt_core! {
+cfg_rt! {
pub(crate) fn spawn_handle() -> Option<crate::runtime::Spawner> {
CONTEXT.with(|ctx| match *ctx.borrow() {
Some(ref ctx) => Some(ctx.spawner.clone()),
@@ -50,24 +60,20 @@ cfg_rt_core! {
/// Set this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: Handle
-pub(crate) fn enter<F, R>(new: Handle, f: F) -> R
-where
- F: FnOnce() -> R,
-{
- struct DropGuard(Option<Handle>);
-
- impl Drop for DropGuard {
- fn drop(&mut self) {
- CONTEXT.with(|ctx| {
- *ctx.borrow_mut() = self.0.take();
- });
- }
- }
-
- let _guard = CONTEXT.with(|ctx| {
+pub(crate) fn enter(new: Handle) -> EnterGuard {
+ CONTEXT.with(|ctx| {
let old = ctx.borrow_mut().replace(new);
- DropGuard(old)
- });
+ EnterGuard(old)
+ })
+}
+
+#[derive(Debug)]
+pub(crate) struct EnterGuard(Option<Handle>);
- f()
+impl Drop for EnterGuard {
+ fn drop(&mut self) {
+ CONTEXT.with(|ctx| {
+ *ctx.borrow_mut() = self.0.take();
+ });
+ }
}