From 7252f54a9317ce52ce97cf0fa92759af2d0db17e Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 27 Oct 2022 13:15:59 -0700 Subject: [PATCH] rt: move internal clock fns out of context A step towards getting rid of `runtime::context`. Internal functions related to getting the current clock are moved to the time driver. --- tokio/src/runtime/context.rs | 16 ---------------- tokio/src/time/clock.rs | 8 +++++++- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/tokio/src/runtime/context.rs b/tokio/src/runtime/context.rs index c816959c17d..afa8c3f2e4f 100644 --- a/tokio/src/runtime/context.rs +++ b/tokio/src/runtime/context.rs @@ -24,22 +24,6 @@ pub(crate) fn current() -> Handle { } } -cfg_time! { - cfg_test_util! { - pub(crate) fn clock() -> Option { - match CONTEXT.try_with(|ctx| { - let ctx = ctx.borrow(); - ctx - .as_ref() - .map(|ctx| ctx.inner.clock().clone()) - }) { - Ok(clock) => clock, - Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR), - } - } - } -} - /// Sets this [`Handle`] as the current active [`Handle`]. /// /// [`Handle`]: Handle diff --git a/tokio/src/time/clock.rs b/tokio/src/time/clock.rs index c3b180eb5c6..01ab50d38a9 100644 --- a/tokio/src/time/clock.rs +++ b/tokio/src/time/clock.rs @@ -33,7 +33,13 @@ cfg_test_util! { cfg_rt! { fn clock() -> Option { - crate::runtime::context::clock() + use crate::runtime::Handle; + + match Handle::try_current() { + Ok(handle) => Some(handle.inner.clock().clone()), + Err(ref e) if e.is_missing_context() => None, + Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR), + } } }