Skip to content

Commit 1b818a3

Browse files
committed
time: update wake_up while holding all the locks of sharded time wheels
1 parent 14c17fc commit 1b818a3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tokio/src/runtime/time/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,24 @@ impl Driver {
190190
assert!(!handle.is_shutdown());
191191

192192
// Finds out the min expiration time to park.
193-
let expiration_time = (0..rt_handle.time().inner.get_shard_size())
194-
.filter_map(|id| {
195-
let lock = rt_handle.time().inner.lock_sharded_wheel(id);
196-
lock.next_expiration_time()
197-
})
193+
let locks = (0..rt_handle.time().inner.get_shard_size())
194+
.map(|id| rt_handle.time().inner.lock_sharded_wheel(id))
195+
.collect::<Vec<_>>();
196+
197+
let expiration_time = locks
198+
.iter()
199+
.filter_map(|lock| lock.next_expiration_time())
198200
.min();
199201

200202
rt_handle
201203
.time()
202204
.inner
203205
.next_wake
204206
.store(next_wake_time(expiration_time));
205-
207+
208+
// Safety: After updating the `next_wake`, we drop all the locks.
209+
drop(locks);
210+
206211
match expiration_time {
207212
Some(when) => {
208213
let now = handle.time_source.now(rt_handle.clock());

0 commit comments

Comments
 (0)