Re: [PATCH 2/6] rust: hrtimer: Add HrTimerCallbackContext and ::forward()

Andreas Hindborg
2025-04-10T06:21:58Z

"Lyude Paul" <lyude@redhat.com> writes:

> On Wed, 2025-04-09 at 12:58 -0400, Lyude Paul wrote:
>>
>> Pin<&'a T> is noticeably absent, because I'm not sure it could fulfill these
>> requirements. That being said - assuming we fulfill the unique ownership
>> requirement, I believe that for all the unique aforementioned types it
>> wouldn't be possible to take out a timer handle when they're in scope anyhow.
>> So we probably could skip the cancel() call?
>
> Nope - realizing this doesn't solve the edge case of "what if someone tried
> calling a contextless forward() from within the context of the timer callback
> itself" since uniqueness doesn't actually mean the timer is cancelled. So I
> think your suggestion of returning Err() if the timer is already running might
> actually be the way to go here. I think we would still need to ensure
> uniqueness though, since that can at least guarantee that the timer won't be
> requeued between us checking it and before we manage to call
> hrtimer_forward().

We should not be able to obtain a unique reference/pointer when the
timer is armed. In this case the timer handle will somehow own the
timer, either directly, by refcount, or by reference.

At any rate, you can add this to the current series, or you can submit
it later as a separate series. I don't think we need to stall the
current series till we figure this out. But it is good to keep it in mind.

Best regards,
Andreas Hindborg