Skip to content

Commit

Permalink
rt: move internal clock fns out of context (#5139)
Browse files Browse the repository at this point in the history
A step towards getting rid of `runtime::context`. Internal functions
related to getting the current clock are moved to the time driver.
  • Loading branch information
carllerche committed Oct 27, 2022
1 parent 6c19748 commit 5c2e275
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
16 changes: 0 additions & 16 deletions tokio/src/runtime/context.rs
Expand Up @@ -24,22 +24,6 @@ pub(crate) fn current() -> Handle {
}
}

cfg_time! {
cfg_test_util! {
pub(crate) fn clock() -> Option<crate::runtime::driver::Clock> {
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
Expand Down
8 changes: 7 additions & 1 deletion tokio/src/time/clock.rs
Expand Up @@ -33,7 +33,13 @@ cfg_test_util! {

cfg_rt! {
fn clock() -> Option<Clock> {
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),
}
}
}

Expand Down

0 comments on commit 5c2e275

Please sign in to comment.