Re: [PATCH v3] rust: hrtimer: add active() method to query timer state
From: FUJITA Tomonori
Date: Sat Nov 14 2026 - 08:38:49 EST
On Thu, 12 Nov 2026 09:55:05 +0100
Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
> FUJITA Tomonori <tomo@xxxxxxxxxxxx> writes:
>
>>> + /// Query the state of the timer.
>>> + ///
>>> + /// Returns [`true`] if the timer is in the started or running states.
>>> + ///
>>> + /// This method synchronizes internally and does not require exclusive access to the timer.
>>> + ///
>>> + /// The returned value is a snapshot. A concurrent start or expiry can change the state of the
>>> + /// timer right after this method returns, so callers that need the state to be stable must
>>> + /// serialize against those operations by other means.
>>
>> Does "expiry" here mean that the callback returns HrTimerRestart::NoRestart
>> on another CPU? An expiry alone moves the timer from started to running, so
>> active() still returns true. If so, I think it is clearer to write this case
>> directly, and to add the case where the timer is canceled on another CPU.
>>
>> The same sentence is in the commit message, so please update it too.
>
> Right. How about this:
>
> The returned value is a snapshot. A concurrent evnet can change the state of the
> timer right after this method returns, so callers that need the state to be stable must
> serialize against those operations by other means.
>
> The intention is not to reiterate the state machine, but to indicate
> that things might changes.
Looks good to me, except for one small point. Since "start or expiry"
was removed, it's not clear what "those operations" refers to. How
about something like:
must serialize against such events by other means.
Also typo: evnet -> event