diff --git a/tokio/src/runtime/time/entry.rs b/tokio/src/runtime/time/entry.rs index 7991ee0dc..acf8f2f39 100644 --- a/tokio/src/runtime/time/entry.rs +++ b/tokio/src/runtime/time/entry.rs @@ -69,7 +69,7 @@ use std::{marker::PhantomPinned, pin::Pin, ptr::NonNull}; type TimerResult = Result<(), crate::time::error::Error>; -const STATE_DEREGISTERED: u64 = u64::MAX; +pub(in crate::runtime::time) const STATE_DEREGISTERED: u64 = u64::MAX; const STATE_PENDING_FIRE: u64 = STATE_DEREGISTERED - 1; const STATE_MIN_VALUE: u64 = STATE_PENDING_FIRE; /// The largest safe integer to use for ticks. @@ -273,7 +273,7 @@ impl StateCell { /// ordering, but is conservative - if it returns false, the timer is /// definitely _not_ registered. pub(super) fn might_be_registered(&self) -> bool { - self.state.load(Ordering::Relaxed) != u64::MAX + self.state.load(Ordering::Relaxed) != STATE_DEREGISTERED } } @@ -612,7 +612,7 @@ impl TimerHandle { match self.inner.as_ref().state.mark_pending(not_after) { Ok(()) => { // mark this as being on the pending queue in cached_when - self.inner.as_ref().set_cached_when(u64::MAX); + self.inner.as_ref().set_cached_when(STATE_DEREGISTERED); Ok(()) } Err(tick) => { diff --git a/tokio/src/runtime/time/mod.rs b/tokio/src/runtime/time/mod.rs index 8cd51c5cb..024fe77e9 100644 --- a/tokio/src/runtime/time/mod.rs +++ b/tokio/src/runtime/time/mod.rs @@ -92,10 +92,10 @@ pub(crate) struct Driver { /// Timer state shared between `Driver`, `Handle`, and `Registration`. struct Inner { // The state is split like this so `Handle` can access `is_shutdown` without locking the mutex - pub(super) state: Mutex, + state: Mutex, /// True if the driver is being shutdown. - pub(super) is_shutdown: AtomicBool, + is_shutdown: AtomicBool, // When `true`, a call to `park_timeout` should immediately return and time // should not advance. One reason for this to be `true` is if the task @@ -171,7 +171,7 @@ impl Driver { fn park_internal(&mut self, rt_handle: &driver::Handle, limit: Option) { let handle = rt_handle.time(); - let mut lock = handle.inner.state.lock(); + let mut lock = handle.inner.lock(); assert!(!handle.is_shutdown()); diff --git a/tokio/src/runtime/time/wheel/mod.rs b/tokio/src/runtime/time/wheel/mod.rs index 7040fc146..c0459ee73 100644 --- a/tokio/src/runtime/time/wheel/mod.rs +++ b/tokio/src/runtime/time/wheel/mod.rs @@ -7,6 +7,7 @@ use self::level::Level; use std::{array, ptr::NonNull}; +use super::entry::STATE_DEREGISTERED; use super::EntryList; /// Timing wheel implementation. @@ -117,7 +118,7 @@ impl Wheel { pub(crate) unsafe fn remove(&mut self, item: NonNull) { unsafe { let when = item.as_ref().cached_when(); - if when == u64::MAX { + if when == STATE_DEREGISTERED { self.pending.remove(item); } else { debug_assert!(