Skip to content

Commit

Permalink
time: update wake_up while holding all the locks of sharded time wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
wathenjiang committed Jul 16, 2024
1 parent 14c17fc commit 35f94c1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tokio/src/runtime/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,23 @@ impl Driver {
assert!(!handle.is_shutdown());

// Finds out the min expiration time to park.
let expiration_time = (0..rt_handle.time().inner.get_shard_size())
.filter_map(|id| {
let lock = rt_handle.time().inner.lock_sharded_wheel(id);
lock.next_expiration_time()
})
let locks = (0..rt_handle.time().inner.get_shard_size())
.map(|id| rt_handle.time().inner.lock_sharded_wheel(id))
.collect::<Vec<_>>();

let expiration_time = locks
.iter()
.filter_map(|lock| lock.next_expiration_time())
.min();

rt_handle
.time()
.inner
.next_wake
.store(next_wake_time(expiration_time));

// Safety: After updating the `next_wake`, we drop all the locks.
drop(locks);

match expiration_time {
Some(when) => {
let now = handle.time_source.now(rt_handle.clock());
Expand Down

0 comments on commit 35f94c1

Please sign in to comment.