mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
time: address style issues (#7328)
This commit is contained in:
@@ -69,7 +69,7 @@ use std::{marker::PhantomPinned, pin::Pin, ptr::NonNull};
|
|||||||
|
|
||||||
type TimerResult = Result<(), crate::time::error::Error>;
|
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_PENDING_FIRE: u64 = STATE_DEREGISTERED - 1;
|
||||||
const STATE_MIN_VALUE: u64 = STATE_PENDING_FIRE;
|
const STATE_MIN_VALUE: u64 = STATE_PENDING_FIRE;
|
||||||
/// The largest safe integer to use for ticks.
|
/// 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
|
/// ordering, but is conservative - if it returns false, the timer is
|
||||||
/// definitely _not_ registered.
|
/// definitely _not_ registered.
|
||||||
pub(super) fn might_be_registered(&self) -> bool {
|
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) {
|
match self.inner.as_ref().state.mark_pending(not_after) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
// mark this as being on the pending queue in cached_when
|
// 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(tick) => {
|
Err(tick) => {
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ pub(crate) struct Driver {
|
|||||||
/// Timer state shared between `Driver`, `Handle`, and `Registration`.
|
/// Timer state shared between `Driver`, `Handle`, and `Registration`.
|
||||||
struct Inner {
|
struct Inner {
|
||||||
// The state is split like this so `Handle` can access `is_shutdown` without locking the mutex
|
// The state is split like this so `Handle` can access `is_shutdown` without locking the mutex
|
||||||
pub(super) state: Mutex<InnerState>,
|
state: Mutex<InnerState>,
|
||||||
|
|
||||||
/// True if the driver is being shutdown.
|
/// 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
|
// 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
|
// 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<Duration>) {
|
fn park_internal(&mut self, rt_handle: &driver::Handle, limit: Option<Duration>) {
|
||||||
let handle = rt_handle.time();
|
let handle = rt_handle.time();
|
||||||
let mut lock = handle.inner.state.lock();
|
let mut lock = handle.inner.lock();
|
||||||
|
|
||||||
assert!(!handle.is_shutdown());
|
assert!(!handle.is_shutdown());
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use self::level::Level;
|
|||||||
|
|
||||||
use std::{array, ptr::NonNull};
|
use std::{array, ptr::NonNull};
|
||||||
|
|
||||||
|
use super::entry::STATE_DEREGISTERED;
|
||||||
use super::EntryList;
|
use super::EntryList;
|
||||||
|
|
||||||
/// Timing wheel implementation.
|
/// Timing wheel implementation.
|
||||||
@@ -117,7 +118,7 @@ impl Wheel {
|
|||||||
pub(crate) unsafe fn remove(&mut self, item: NonNull<TimerShared>) {
|
pub(crate) unsafe fn remove(&mut self, item: NonNull<TimerShared>) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let when = item.as_ref().cached_when();
|
let when = item.as_ref().cached_when();
|
||||||
if when == u64::MAX {
|
if when == STATE_DEREGISTERED {
|
||||||
self.pending.remove(item);
|
self.pending.remove(item);
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
|
|||||||
Reference in New Issue
Block a user