Skip to content

Commit

Permalink
time: remove cached elapsed value from driver state (#6097)
Browse files Browse the repository at this point in the history
  • Loading branch information
satakuma committed Nov 5, 2023
1 parent 944024e commit 61fcc3b
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions tokio/src/runtime/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ struct Inner {

/// Time state shared which must be protected by a `Mutex`
struct InnerState {
/// The last published timer `elapsed` value.
elapsed: u64,

/// The earliest time at which we promise to wake up without unparking.
next_wake: Option<NonZeroU64>,

Expand All @@ -132,7 +129,6 @@ impl Driver {
time_source,
inner: Inner {
state: Mutex::new(InnerState {
elapsed: 0,
next_wake: None,
wheel: wheel::Wheel::new(),
}),
Expand Down Expand Up @@ -262,14 +258,14 @@ impl Handle {

let mut lock = self.inner.lock();

if now < lock.elapsed {
if now < lock.wheel.elapsed() {
// Time went backwards! This normally shouldn't happen as the Rust language
// guarantees that an Instant is monotonic, but can happen when running
// Linux in a VM on a Windows host due to std incorrectly trusting the
// hardware clock to be monotonic.
//
// See <https://github.com/tokio-rs/tokio/issues/3619> for more information.
now = lock.elapsed;
now = lock.wheel.elapsed();
}

while let Some(entry) = lock.wheel.poll(now) {
Expand All @@ -296,8 +292,6 @@ impl Handle {
}
}

// Update the elapsed cache
lock.elapsed = lock.wheel.elapsed();
lock.next_wake = lock
.wheel
.poll_at()
Expand Down

0 comments on commit 61fcc3b

Please sign in to comment.