Re: [PATCH 2/6] rust: hrtimer: Add HrTimerCallbackContext and ::forward()
From: Andreas Hindborg
Date: Wed Apr 09 2025 - 03:50:12 EST
"Lyude Paul" <lyude@xxxxxxxxxx> writes:
> On Tue, 2025-04-08 at 13:47 +0200, Andreas Hindborg wrote:
>> "Lyude Paul" <lyude@xxxxxxxxxx> writes:
>>
>> > With Linux's hrtimer API, certain functions require we either acquire
>> > proper locking to call specific methods - or that we call said methods from
>> > the context of the timer callback. hrtimer_forward() is one of these
>> > functions, so we start by adding a new HrTimerCallbackContext type which
>> > provides a way of calling these methods that is inaccessible outside of
>> > hrtimer callbacks.
>>
>> Based on tglx comment, we should be able to call this function if the
>> timer is stopped and we have a unique ownership of the timer. Do you
>> want to add that? If not, could you add a note about this somewhere?
>
>
> Happy to! So, I think if we were to add a function for this I assume we would
> want something like this?
>
> fn forward(&mut self, now: Instant, interval: Duration) -> u64 {
> self.cancel();
> /* Do actual forward stuff here */
> }
>
> Of course with some documentation pointing out that this function will stop
> the timer if required.
Yes, something like that. My first thought was to check if the timer was
running and return `Err` if that is the case. But it might be more
simple to just call `cancel`. What do you think?
Best regards,
Andreas Hindborg