mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-28 05:34:13 -05:00
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>
This commit is contained in:
committed by
Andreas Hindborg
parent
3f2a5ba784
commit
ac0a7bd27f
@@ -212,6 +212,17 @@ pub fn forward(self: Pin<&mut Self>, now: HrTimerInstant<T>, interval: Delta) ->
|
||||
// valid `Self` that we have exclusive access to.
|
||||
unsafe { Self::raw_forward(this, now, interval) }
|
||||
}
|
||||
|
||||
/// Conditionally forward the timer.
|
||||
///
|
||||
/// This is a variant of [`forward()`](Self::forward) that uses an interval after the current
|
||||
/// time of the base clock for the [`HrTimer`].
|
||||
pub fn forward_now(self: Pin<&mut Self>, interval: Delta) -> u64
|
||||
where
|
||||
T: HasHrTimer<T>,
|
||||
{
|
||||
self.forward(HrTimerInstant::<T>::now(), interval)
|
||||
}
|
||||
}
|
||||
|
||||
/// Implemented by pointer types that point to structs that contain a [`HrTimer`].
|
||||
@@ -687,6 +698,14 @@ pub fn forward(&mut self, now: HrTimerInstant<T>, interval: Delta) -> u64 {
|
||||
// - By our type invariants, `self.0` always points to a valid `HrTimer<T>`
|
||||
unsafe { HrTimer::<T>::raw_forward(self.0.as_ptr(), now, interval) }
|
||||
}
|
||||
|
||||
/// Conditionally forward the timer.
|
||||
///
|
||||
/// This is a variant of [`HrTimerCallbackContext::forward()`] that uses an interval after the
|
||||
/// current time of the base clock for the [`HrTimer`].
|
||||
pub fn forward_now(&mut self, duration: Delta) -> u64 {
|
||||
self.forward(HrTimerInstant::<T>::now(), duration)
|
||||
}
|
||||
}
|
||||
|
||||
/// Use to implement the [`HasHrTimer<T>`] trait.
|
||||
|
||||
Reference in New Issue
Block a user