Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
20a1daf
add macro `cfg_rt_and_time` and `cfg_rt_or_time`
ADD-SP Jul 19, 2025
3e65b07
impl `wheel::Entry`
ADD-SP Jul 13, 2025
7618162
remove global timer wheel
ADD-SP Jul 13, 2025
4b0a866
add local timer wheel to the current_thread scheduler
ADD-SP Jul 13, 2025
78d433f
add local timer wheel to the multi_thread scheduler
ADD-SP Jul 13, 2025
4727a56
remove `tokio/src/runtime/time/entry.rs`
ADD-SP Jul 13, 2025
d7f9c72
impl `tokio/src/runtime/time/timer.rs`
ADD-SP Jul 13, 2025
161ca91
adapt the impl of `tokio::time::sleep`
ADD-SP Jul 13, 2025
09b27cf
adapt the impl of `tokio::time::interval`
ADD-SP Jul 13, 2025
58a13e3
let current_thread scheduler process timers
ADD-SP Jul 13, 2025
8407dd6
let multi_thread scheduler process timers
ADD-SP Jul 13, 2025
89e132f
remove the `InsertError`
ADD-SP Jul 17, 2025
9b336b1
fix `tokio-util/tests/time_delay_queue.rs`
ADD-SP Jul 19, 2025
cf7211a
fix unused import `wake_list::WakeList`
ADD-SP Jul 19, 2025
8ac5933
re-enable loom tests for timers
ADD-SP Aug 2, 2025
ca49b99
fix race conditions while operating on `EntryHandle`
ADD-SP Aug 4, 2025
fb027a6
cross-thread cancellation queue
ADD-SP Aug 10, 2025
9e294d5
drop all items while dropping the cancellation queue
ADD-SP Aug 14, 2025
abffd46
switch back to general intrusive node based MPSC
ADD-SP Aug 15, 2025
ccd0ae8
relax the memory ordering
ADD-SP Aug 16, 2025
f91caf7
switch to `Mutex` version of cancellation queue
ADD-SP Aug 15, 2025
88292d8
avoid `noalias` and `drop_in_place`
ADD-SP Aug 16, 2025
bb932b0
remove legacy works in `spellcheck.dic`
ADD-SP Aug 17, 2025
4b15736
reuse the existing intrusice list implementation
ADD-SP Aug 24, 2025
e89259e
fix docstring issue caused by renaming `Entry::cancel_pointer` to `En…
ADD-SP Aug 24, 2025
5eee490
reuse existing intrusive list impl using a ZST
ADD-SP Aug 27, 2025
6626ad0
chore(spellcheck.dic): add 'ZST'
ADD-SP Aug 27, 2025
65276ac
fix memory leakage of cancellation queue
ADD-SP Aug 28, 2025
e4b1e68
remove useless `unsafe impl Send for Entry`
ADD-SP Aug 28, 2025
009d158
clarify the meaning of `STATE_BUSY_REGISTERING`
ADD-SP Aug 28, 2025
c1e0522
merge: sync changes from the base branch
ADD-SP Sep 1, 2025
0f3c9ec
eliminate atomic state by `Mutex<State>` of `Entry`
ADD-SP Sep 1, 2025
6b8eed5
fixup! eliminate atomic state by `Mutex<State>` of `Entry`
ADD-SP Sep 2, 2025
6bb207d
reduce lock contention while drainning the remote timers
ADD-SP Sep 2, 2025
0e9a7e1
merge: sync changes from the base branch
ADD-SP Sep 3, 2025
93ebb38
merge: sync changes from the base branch
ADD-SP Sep 7, 2025
6a4f048
merge: sync changes from the base branch
ADD-SP Sep 8, 2025
2385b3d
improve the cache locality while checking the shutdown flag
ADD-SP Sep 11, 2025
782bcba
merge: sync changes from the base branch
ADD-SP Sep 11, 2025
2fcfb4b
remove unnecessary `PhantomData` in cancellation queue
ADD-SP Sep 11, 2025
9657e6d
fix rustfmt reports
ADD-SP Sep 11, 2025
1fff994
merge: sync changes from the base branch
ADD-SP Sep 15, 2025
c208c3a
ci: fix spellcheck.dic
ADD-SP Sep 15, 2025
fda223d
merge: sync changes from the base branch
ADD-SP Sep 16, 2025
070ddd6
merge: sync changes from the base branch
ADD-SP Sep 16, 2025
102e2d2
merge: sync changes from the base branch
ADD-SP Sep 17, 2025
5d17c33
merge: sync changes from the base branch
ADD-SP Sep 18, 2025
a17bdde
merge: sync changes from the base branch
ADD-SP Sep 19, 2025
40cc384
improve the ergonomic of `Handle::with_wheel()`
ADD-SP Sep 21, 2025
36e71a0
merge: sync changes from the base branch
ADD-SP Sep 21, 2025
a5c384d
merge: sync changes from the base branch
ADD-SP Sep 25, 2025
ebd1df1
merge: sync changes from the base branch
ADD-SP Sep 27, 2025
029da48
merge: sync changes from the base branch
ADD-SP Oct 5, 2025
81e57c9
simplify `tokio/src/runtime/time/timer.rs`
ADD-SP Oct 5, 2025
9b5a90c
fixup! eliminate atomic state by `Mutex<State>` of `Entry`
ADD-SP Oct 6, 2025
4862ef7
push timer tasks into local queue instead of global queue
ADD-SP Oct 6, 2025
89f5968
merge: sync changes from the base branch
ADD-SP Oct 6, 2025
b3c14ea
fixup! simplify `tokio/src/runtime/time/timer.rs`
ADD-SP Oct 6, 2025
2aafc92
fixup! push timer tasks into local queue instead of global queue
ADD-SP Oct 6, 2025
aec80f9
fix `spellcheck.dic`
ADD-SP Oct 6, 2025
8bb88bc
fixup! push timer tasks into local queue instead of global queue
ADD-SP Oct 6, 2025
0b086ec
fixup! push timer tasks into local queue instead of global queue
ADD-SP Oct 6, 2025
35be1b9
fixup! push timer tasks into local queue instead of global queue
ADD-SP Oct 7, 2025
348fc25
merge: sync changes from the base branch
ADD-SP Oct 7, 2025
d00f247
fixup! eliminate atomic state by `Mutex<State>` of `Entry`
ADD-SP Oct 8, 2025
c5eeb3d
fixup! eliminate atomic state by `Mutex<State>` of `Entry`
ADD-SP Oct 8, 2025
5215089
cleanup the `Context::park_internal`
ADD-SP Oct 8, 2025
f595efa
merge: sync changes from the base branch
ADD-SP Oct 10, 2025
57cd244
fix two bugs causes freqently park/unpark
ADD-SP Oct 12, 2025
9d7b03d
merge: sync changes from the base branch
ADD-SP Oct 12, 2025
88cd24b
fixup! fix two bugs causes freqently park/unpark
ADD-SP Oct 12, 2025
99a084f
fix `spellcheck.dic`
ADD-SP Oct 12, 2025
980c977
wake up the defer task correctly in the current thread runtime
ADD-SP Oct 12, 2025
5d6cf22
merge: sync changes from the base branch
ADD-SP Oct 14, 2025
ea37b23
cancel the timer locally if possible
ADD-SP Oct 16, 2025
9bf117d
merge: sync changes from the base branch
ADD-SP Oct 16, 2025
df81bbd
fixup! cancel the timer locally if possible
ADD-SP Oct 16, 2025
88d3596
fixup! cancel the timer locally if possible
ADD-SP Oct 16, 2025
ef78794
merge: sync changes from the base branch
ADD-SP Oct 18, 2025
d8b47b9
small refactor of cancellation code path
ADD-SP Oct 18, 2025
9cddfda
merge: sync changes from the base branch
ADD-SP Oct 18, 2025
63a93c2
bump the wasm memory limit for doc-tests
ADD-SP Oct 18, 2025
aa413dd
fix potenial mem leak when dropping timer
ADD-SP Oct 21, 2025
5e5312a
runtime: improve style by reducing indent level
ADD-SP Oct 21, 2025
1c59461
merge: sync changes from the base branch
ADD-SP Oct 21, 2025
94d40e3
fix memory leak when draining the cancel queue
ADD-SP Oct 21, 2025
a5c3026
merge: sync changes from the base branch
ADD-SP Oct 21, 2025
17922c2
remove debugging code
ADD-SP Oct 21, 2025
c47aa24
fix unused import error
ADD-SP Oct 21, 2025
47f4036
remove debug print
Oct 22, 2025
5b53771
fix heap-use-after-free issue
ADD-SP Oct 22, 2025
47e04e8
remove legacy comments of `Wheel::insert()`
ADD-SP Oct 24, 2025
fca1e42
merge: sync changes from the base branch
ADD-SP Oct 24, 2025
15b0563
handle the spurious wakeup of condvar in multi-thread runtime
ADD-SP Oct 26, 2025
d9ff6b8
merge: sync changes from the base branch
ADD-SP Oct 26, 2025
22a3771
merge: sync changes from the base branch
ADD-SP Oct 31, 2025
a6a0a85
merge: sync changes from the base branch
ADD-SP Nov 5, 2025
ba627cf
merge: sync changes from the base branch
ADD-SP Nov 6, 2025
89b71f3
merge: sync changes from the base branch
ADD-SP Nov 8, 2025
522252f
merge: sync changes from the base branch
ADD-SP Nov 9, 2025
e3102f7
fix reports of `unsafe_op_in_unsafe_fn`
ADD-SP Nov 9, 2025
4082cba
merge: sync changes from the base branch
ADD-SP Nov 11, 2025
36bf961
merge: sync changes from the base branch
ADD-SP Nov 13, 2025
cde17cd
unlock the mutex before droping the waker
ADD-SP Nov 13, 2025
9a4d439
don't cancel the timer locally due to `block_in_place` migrates the `…
ADD-SP Nov 13, 2025
d4959a8
fix incorrect comment of `TransitionToRegistered`
ADD-SP Nov 13, 2025
bc243b8
eliminate `Option<Context2>` in `Core`
ADD-SP Nov 16, 2025
ccdd80b
merge: sync changes from the base branch
ADD-SP Nov 16, 2025
0bd9db2
remove useless `Send` and `Sync` impl
ADD-SP Nov 16, 2025
7e824dc
fixup! eliminate `Option<Context2>` in `Core`
ADD-SP Nov 16, 2025
38b49ba
fix error reports of `cargo hack`
ADD-SP Nov 16, 2025
e45109f
simplify the `PrivState`
ADD-SP Nov 18, 2025
bedf058
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
1a82da1
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
4b31afa
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
058e4f3
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
133b962
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
bcf92c4
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
ed80712
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
91d759f
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
59a0d91
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
f2d5868
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
f17b43f
fixup! simplify the `PrivState`
ADD-SP Nov 18, 2025
aebf2b3
add safety comments in `entry.rs`
ADD-SP Nov 19, 2025
6f5735e
tolerate spurious wakeup
ADD-SP Nov 19, 2025
0215b54
move the `crate::runtime::scheduler::util` out of the `cfg_rt_and_tim…
ADD-SP Nov 19, 2025
ef4c37f
improve the test coverage of timer cancellation
ADD-SP Nov 19, 2025
b72f924
fixup! improve the test coverage of timer cancellation
ADD-SP Nov 19, 2025
c1a8676
revert spurious changes
ADD-SP Nov 19, 2025
b63057c
isolate two kinds of timer implementations
ADD-SP Nov 25, 2025
cdf6994
merge: sync changes from the base branch
ADD-SP Nov 25, 2025
e4ed82c
fix rustfmt reports
ADD-SP Nov 25, 2025
91eb3e1
revert `tokio-util/tests/time_delay_queue.rs` as it is using the exis…
ADD-SP Nov 25, 2025
4465bab
improve the test coverage
ADD-SP Nov 25, 2025
804f799
fixup! improve the test coverage
ADD-SP Nov 25, 2025
f611539
improve style
ADD-SP Nov 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ jobs:
CARGO_TARGET_WASM32_WASIP1_RUNNER: "wasmtime run --"
CARGO_TARGET_WASM32_WASIP1_THREADS_RUNNER: "wasmtime run -W bulk-memory=y -W threads=y -S threads=y --"
RUSTFLAGS: --cfg tokio_unstable -Dwarnings -C target-feature=+atomics,+bulk-memory -C link-args=--max-memory=67108864
RUSTDOCFLAGS: -C link-args=--max-memory=67108864
Copy link
Copy Markdown
Member Author

@ADD-SP ADD-SP Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

/// let mut data = vec![0; 16 * 1024];


- name: WASI test tokio-stream
run: cargo test -p tokio-stream --target ${{ matrix.target }} --features time,net,io-util,sync
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/loom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
toolchain: ${{ env.rust_stable }}
- uses: Swatinem/rust-cache@v2
- name: run tests
run: cargo test --lib --release --features full -- --nocapture runtime::time::tests
run: cargo test --lib --release --features full -- --nocapture runtime::time
working-directory: tokio

loom-current-thread:
Expand Down
5 changes: 4 additions & 1 deletion spellcheck.dic
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
308
311
&
+
<
Expand Down Expand Up @@ -64,6 +64,7 @@ codec
codecs
combinator
combinators
condvar
config
Config
connectionless
Expand Down Expand Up @@ -163,6 +164,7 @@ Lauck
libc
lifecycle
lifo
LLVM
lookups
macOS
MacOS
Expand Down Expand Up @@ -307,3 +309,4 @@ Wakers
wakeup
wakeups
workstealing
ZST
1 change: 1 addition & 0 deletions tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ tokio-test = { version = "0.4.0", path = "../tokio-test" }
tokio-stream = { version = "0.1", path = "../tokio-stream" }
tokio-util = { version = "0.7", path = "../tokio-util", features = ["rt"] }
futures = { version = "0.3.0", features = ["async-await"] }
futures-test = "0.3.31"
mockall = "0.13.0"
async-stream = "0.3"
futures-concurrency = "7.6.3"
Expand Down
49 changes: 47 additions & 2 deletions tokio/src/runtime/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![cfg_attr(loom, allow(unused_imports))]

use crate::runtime::handle::Handle;
use crate::runtime::{blocking, driver, Callback, HistogramBuilder, Runtime, TaskCallback};
use crate::runtime::{
blocking, driver, Callback, HistogramBuilder, Runtime, TaskCallback, TimerFlavor,
};
#[cfg(tokio_unstable)]
use crate::runtime::{metrics::HistogramConfiguration, LocalOptions, LocalRuntime, TaskMeta};
use crate::util::rand::{RngSeed, RngSeedGenerator};
Expand Down Expand Up @@ -133,6 +135,8 @@ pub struct Builder {

#[cfg(tokio_unstable)]
pub(super) unhandled_panic: UnhandledPanic,

timer_flavor: TimerFlavor,
}

cfg_unstable! {
Expand Down Expand Up @@ -318,6 +322,8 @@ impl Builder {
metrics_poll_count_histogram: HistogramBuilder::default(),

disable_lifo_slot: false,

timer_flavor: TimerFlavor::Traditional,
}
}

Expand Down Expand Up @@ -363,6 +369,41 @@ impl Builder {
self
}

/// Enables the alternative timer implementation, which is disabled by default.
///
/// The alternative timer implementation is an unstable feature that may
/// provide better performance on multi-threaded runtimes with a large number
/// of worker threads.
///
/// This option only applies to multi-threaded runtimes. Attempting to use
/// this option with any other runtime type will have no effect.
///
/// [Click here to share your experience with the alternative timer](https://github.com/tokio-rs/tokio/issues/7745)
///
/// # Examples
///
/// ```
/// # #[cfg(not(target_family = "wasm"))]
/// # {
/// use tokio::runtime;
///
/// let rt = runtime::Builder::new_multi_thread()
/// .enable_alt_timer()
/// .build()
/// .unwrap();
/// # }
/// ```
#[cfg(all(tokio_unstable, feature = "time", feature = "rt-multi-thread"))]
#[cfg_attr(
docsrs,
doc(cfg(all(tokio_unstable, feature = "time", feature = "rt-multi-thread")))
)]
pub fn enable_alt_timer(&mut self) -> &mut Self {
self.enable_time();
self.timer_flavor = TimerFlavor::Alternative;
self
}

/// Sets the number of worker threads the `Runtime` will use.
///
/// This can be any number above 0 though it is advised to keep this value
Expand Down Expand Up @@ -992,6 +1033,7 @@ impl Builder {
enable_time: self.enable_time,
start_paused: self.start_paused,
nevents: self.nevents,
timer_flavor: self.timer_flavor,
}
}

Expand Down Expand Up @@ -1544,7 +1586,9 @@ impl Builder {
use crate::runtime::scheduler;
use crate::runtime::Config;

let (driver, driver_handle) = driver::Driver::new(self.get_cfg())?;
let mut cfg = self.get_cfg();
cfg.timer_flavor = TimerFlavor::Traditional;
let (driver, driver_handle) = driver::Driver::new(cfg)?;

// Blocking pool
let blocking_pool = blocking::create_blocking_pool(self, self.max_blocking_threads);
Expand Down Expand Up @@ -1761,6 +1805,7 @@ cfg_rt_multi_thread! {
seed_generator: seed_generator_1,
metrics_poll_count_histogram: self.metrics_poll_count_histogram_builder(),
},
self.timer_flavor,
);

let handle = Handle { inner: scheduler::Handle::MultiThread(handle) };
Expand Down
31 changes: 27 additions & 4 deletions tokio/src/runtime/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub(crate) struct Cfg {
pub(crate) enable_pause_time: bool,
pub(crate) start_paused: bool,
pub(crate) nevents: usize,
pub(crate) timer_flavor: crate::runtime::TimerFlavor,
}

impl Driver {
Expand All @@ -48,7 +49,8 @@ impl Driver {

let clock = create_clock(cfg.enable_pause_time, cfg.start_paused);

let (time_driver, time_handle) = create_time_driver(cfg.enable_time, io_stack, &clock);
let (time_driver, time_handle) =
create_time_driver(cfg.enable_time, cfg.timer_flavor, io_stack, &clock);

Ok((
Self { inner: time_driver },
Expand Down Expand Up @@ -113,6 +115,14 @@ impl Handle {
.expect("A Tokio 1.x context was found, but timers are disabled. Call `enable_time` on the runtime builder to enable timers.")
}

#[cfg(tokio_unstable)]
pub(crate) fn with_time<F, R>(&self, f: F) -> R
where
F: FnOnce(Option<&crate::runtime::time::Handle>) -> R,
{
f(self.time.as_ref())
}

pub(crate) fn clock(&self) -> &Clock {
&self.clock
}
Expand Down Expand Up @@ -281,6 +291,7 @@ cfg_time! {
Enabled {
driver: crate::runtime::time::Driver,
},
EnabledAlt(IoStack),
Disabled(IoStack),
}

Expand All @@ -293,13 +304,21 @@ cfg_time! {

fn create_time_driver(
enable: bool,
timer_flavor: crate::runtime::TimerFlavor,
io_stack: IoStack,
clock: &Clock,
) -> (TimeDriver, TimeHandle) {
if enable {
let (driver, handle) = crate::runtime::time::Driver::new(io_stack, clock);

(TimeDriver::Enabled { driver }, Some(handle))
match timer_flavor {
crate::runtime::TimerFlavor::Traditional => {
let (driver, handle) = crate::runtime::time::Driver::new(io_stack, clock);
(TimeDriver::Enabled { driver }, Some(handle))
}
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
crate::runtime::TimerFlavor::Alternative => {
(TimeDriver::EnabledAlt(io_stack), Some(crate::runtime::time::Driver::new_alt(clock)))
}
}
} else {
(TimeDriver::Disabled(io_stack), None)
}
Expand All @@ -309,20 +328,23 @@ cfg_time! {
pub(crate) fn park(&mut self, handle: &Handle) {
match self {
TimeDriver::Enabled { driver, .. } => driver.park(handle),
TimeDriver::EnabledAlt(v) => v.park(handle),
TimeDriver::Disabled(v) => v.park(handle),
}
}

pub(crate) fn park_timeout(&mut self, handle: &Handle, duration: Duration) {
match self {
TimeDriver::Enabled { driver } => driver.park_timeout(handle, duration),
TimeDriver::EnabledAlt(v) => v.park_timeout(handle, duration),
TimeDriver::Disabled(v) => v.park_timeout(handle, duration),
}
}

pub(crate) fn shutdown(&mut self, handle: &Handle) {
match self {
TimeDriver::Enabled { driver } => driver.shutdown(handle),
TimeDriver::EnabledAlt(v) => v.shutdown(handle),
TimeDriver::Disabled(v) => v.shutdown(handle),
}
}
Expand All @@ -341,6 +363,7 @@ cfg_not_time! {

fn create_time_driver(
_enable: bool,
_timer_flavor: crate::runtime::TimerFlavor,
io_stack: IoStack,
_clock: &Clock,
) -> (TimeDriver, TimeHandle) {
Expand Down
127 changes: 127 additions & 0 deletions tokio/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,135 @@ cfg_process_driver! {
mod process;
}

#[cfg_attr(not(feature = "time"), allow(dead_code))]
#[derive(Debug, Copy, Clone, PartialEq)]
pub(crate) enum TimerFlavor {
Traditional,
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Alternative,
}

cfg_time! {
pub(crate) mod time;

#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
pub(crate) mod time_alt;

use std::task::{Context, Poll};
use std::pin::Pin;

#[derive(Debug)]
pub(crate) enum Timer {
Traditional(time::TimerEntry),

#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Alternative(time_alt::Timer),
}

impl Timer {
#[track_caller]
pub(crate) fn new(
handle: crate::runtime::scheduler::Handle,
deadline: crate::time::Instant,
) -> Self {
match handle.timer_flavor() {
crate::runtime::TimerFlavor::Traditional => {
Timer::Traditional(time::TimerEntry::new(handle, deadline))
}
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
crate::runtime::TimerFlavor::Alternative => {
Timer::Alternative(time_alt::Timer::new(handle, deadline))
}
}
}

pub(crate) fn deadline(&self) -> crate::time::Instant {
match self {
Timer::Traditional(entry) => entry.deadline(),
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Timer::Alternative(entry) => entry.deadline(),
}
}

pub(crate) fn is_elapsed(&self) -> bool {
match self {
Timer::Traditional(entry) => entry.is_elapsed(),
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Timer::Alternative(entry) => entry.is_elapsed(),
}
}

pub(crate) fn flavor(self: Pin<&Self>) -> TimerFlavor {
match self.get_ref() {
Timer::Traditional(_) => TimerFlavor::Traditional,
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Timer::Alternative(_) => TimerFlavor::Alternative,
}
}

pub(crate) fn reset(
self: Pin<&mut Self>,
new_time: crate::time::Instant,
reregister: bool
) {
// Safety: we never move the inner entries.
let this = unsafe { self.get_unchecked_mut() };
match this {
Timer::Traditional(entry) => {
// Safety: we never move the inner entries.
unsafe { Pin::new_unchecked(entry).reset(new_time, reregister); }
}
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Timer::Alternative(_) => panic!("not implemented yet"),
}
}

pub(crate) fn poll_elapsed(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), crate::time::error::Error>> {
// Safety: we never move the inner entries.
let this = unsafe { self.get_unchecked_mut() };
match this {
Timer::Traditional(entry) => {
// Safety: we never move the inner entries.
unsafe { Pin::new_unchecked(entry).poll_elapsed(cx) }
}
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Timer::Alternative(entry) => {
// Safety: we never move the inner entries.
unsafe { Pin::new_unchecked(entry).poll_elapsed(cx).map(Ok) }
}
}
}

#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
pub(crate) fn scheduler_handle(&self) -> &crate::runtime::scheduler::Handle {
match self {
Timer::Traditional(_) => unreachable!("we should not call this on Traditional Timer"),
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Timer::Alternative(entry) => entry.scheduler_handle(),
}
}

#[cfg(all(tokio_unstable, feature = "tracing"))]
pub(crate) fn driver(self: Pin<&Self>) -> &crate::runtime::time::Handle {
match self.get_ref() {
Timer::Traditional(entry) => entry.driver(),
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Timer::Alternative(entry) => entry.driver(),
}
}

#[cfg(all(tokio_unstable, feature = "tracing"))]
pub(crate) fn clock(self: Pin<&Self>) -> &crate::time::Clock {
match self.get_ref() {
Timer::Traditional(entry) => entry.clock(),
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
Timer::Alternative(entry) => entry.clock(),
}
}
}
}

cfg_signal_internal_and_unix! {
Expand Down
Loading