diff options
author | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2025-06-10 18:32:54 +0900 |
---|---|---|
committer | Andreas Hindborg <a.hindborg@kernel.org> | 2025-06-16 15:01:37 +0200 |
commit | 1664a671be46a0b0daf5250eb124d94a5501a64c (patch) | |
tree | 25bb29707b46024c185ca5ad2a4d5db4fe2325b1 /rust/kernel/time | |
parent | 1b7bbd5975279a1cf8d907fbc719f350031194c2 (diff) |
rust: time: Replace ClockId enum with ClockSource trait
Replace the ClockId enum with a trait-based abstraction called
ClockSource. This change enables expressing clock sources as types and
leveraging the Rust type system to enforce clock correctness at
compile time.
This also sets the stage for future generic abstractions over Instant
types such as Instant<C>.
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Link: https://lore.kernel.org/r/20250610093258.3435874-2-fujita.tomonori@gmail.com
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Diffstat (limited to 'rust/kernel/time')
-rw-r--r-- | rust/kernel/time/hrtimer.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 36e1290cd079..20b87a4d65ae 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -67,7 +67,7 @@ //! A `restart` operation on a timer in the **stopped** state is equivalent to a //! `start` operation. -use super::ClockId; +use super::ClockSource; use crate::{prelude::*, types::Opaque}; use core::marker::PhantomData; use pin_init::PinInit; @@ -112,7 +112,7 @@ unsafe impl<T> Sync for HrTimer<T> {} impl<T> HrTimer<T> { /// Return an initializer for a new timer instance. - pub fn new(mode: HrTimerMode, clock: ClockId) -> impl PinInit<Self> + pub fn new<U: ClockSource>(mode: HrTimerMode) -> impl PinInit<Self> where T: HrTimerCallback, { @@ -126,7 +126,7 @@ impl<T> HrTimer<T> { bindings::hrtimer_setup( place, Some(T::Pointer::run), - clock.into_c(), + U::ID, mode.into_c(), ); } |