@@ -181,6 +181,37 @@ pub trait HrTimerPointer: Sync + Sized {
181181 fn start ( self , expires : Ktime ) -> Self :: TimerHandle ;
182182}
183183
184+ /// Unsafe version of [`HrTimerPointer`] for situations where leaking the
185+ /// [`HrTimerHandle`] returned by `start` would be unsound. This is the case for
186+ /// stack allocated timers.
187+ ///
188+ /// Typical implementers are pinned references such as [`Pin<&T>`].
189+ ///
190+ /// # Safety
191+ ///
192+ /// Implementers of this trait must ensure that instances of types implementing
193+ /// [`UnsafeHrTimerPointer`] outlives any associated [`HrTimerPointer::TimerHandle`]
194+ /// instances.
195+ pub unsafe trait UnsafeHrTimerPointer : Sync + Sized {
196+ /// A handle representing a running timer.
197+ ///
198+ /// # Safety
199+ ///
200+ /// If the timer is running, or if the timer callback is executing when the
201+ /// handle is dropped, the drop method of [`Self::TimerHandle`] must not return
202+ /// until the timer is stopped and the callback has completed.
203+ type TimerHandle : HrTimerHandle ;
204+
205+ /// Start the timer after `expires` time units. If the timer was already
206+ /// running, it is restarted at the new expiry time.
207+ ///
208+ /// # Safety
209+ ///
210+ /// Caller promises keep the timer structure alive until the timer is dead.
211+ /// Caller can ensure this by not leaking the returned [`Self::TimerHandle`].
212+ unsafe fn start ( self , expires : Ktime ) -> Self :: TimerHandle ;
213+ }
214+
184215/// Implemented by [`HrTimerPointer`] implementers to give the C timer callback a
185216/// function to call.
186217// This is split from `HrTimerPointer` to make it easier to specify trait bounds.
0 commit comments