Messages in this thread | | | From | Thomas Gleixner <> | Subject | Re: [PATCH] rust: hrtimer: introduce hrtimer support | Date | Tue, 30 Apr 2024 19:05:37 +0200 |
| |
On Fri, Apr 26 2024 at 07:52, Benno Lossin wrote: > On 25.04.24 11:46, Andreas Hindborg wrote: >> +#[pinned_drop] >> +impl<T> PinnedDrop for Timer<T> { >> + fn drop(self: Pin<&mut Self>) { >> + // SAFETY: By struct invariant `self.timer` was initialized by >> + // `hrtimer_init` so by C API contract it is safe to call >> + // `hrtimer_cancel`. >> + unsafe { >> + bindings::hrtimer_cancel(self.timer.get()); >> + } >> + } >> +} > > Why is this needed? The only way to schedule a timer using this API is > by having an `Arc` with a timer-containing struct inside. But to > schedule the `Arc`, you consume one refcount which is then sent to the > timer subsystem. So it is impossible for the refcount to drop below zero > while the timer is scheduled, but not yet running. > Do you need to call `hrtimer_cancel` after/while a timer is running? > > Also is it ok to call `hrtimer_cancel` inside the timer callback? Since > that can happen when the timer callback owns the last refcount.
You cannot invoke hrtimer_cancel() from within the callback. That deadlocks because hrtimer_cancel() waits for the callback to complete.
Thanks,
tglx
| |