Skip to content

Commit ac0a7bd

Browse files
LyudeAndreas Hindborg
authored andcommitted
rust: hrtimer: Add forward_now() to HrTimer and HrTimerCallbackContext
Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://lore.kernel.org/r/20250821193259.964504-6-lyude@redhat.com Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
1 parent 3f2a5ba commit ac0a7bd

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

rust/kernel/time/hrtimer.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ impl<T> HrTimer<T> {
212212
// valid `Self` that we have exclusive access to.
213213
unsafe { Self::raw_forward(this, now, interval) }
214214
}
215+
216+
/// Conditionally forward the timer.
217+
///
218+
/// This is a variant of [`forward()`](Self::forward) that uses an interval after the current
219+
/// time of the base clock for the [`HrTimer`].
220+
pub fn forward_now(self: Pin<&mut Self>, interval: Delta) -> u64
221+
where
222+
T: HasHrTimer<T>,
223+
{
224+
self.forward(HrTimerInstant::<T>::now(), interval)
225+
}
215226
}
216227

217228
/// Implemented by pointer types that point to structs that contain a [`HrTimer`].
@@ -687,6 +698,14 @@ impl<'a, T: HasHrTimer<T>> HrTimerCallbackContext<'a, T> {
687698
// - By our type invariants, `self.0` always points to a valid `HrTimer<T>`
688699
unsafe { HrTimer::<T>::raw_forward(self.0.as_ptr(), now, interval) }
689700
}
701+
702+
/// Conditionally forward the timer.
703+
///
704+
/// This is a variant of [`HrTimerCallbackContext::forward()`] that uses an interval after the
705+
/// current time of the base clock for the [`HrTimer`].
706+
pub fn forward_now(&mut self, duration: Delta) -> u64 {
707+
self.forward(HrTimerInstant::<T>::now(), duration)
708+
}
690709
}
691710

692711
/// Use to implement the [`HasHrTimer<T>`] trait.

0 commit comments

Comments
 (0)