Lines Matching full:timer
5 //! Allows running timer callbacks without doing allocations at the time of
6 //! starting the timer. For now, only one timer per type is allowed.
53 //! A timer is initialized in the **stopped** state. A stopped timer can be
55 //! `start` operation, the timer is in the **started** state. When the timer
56 //! **expires**, the timer enters the **running** state and the handler is
57 //! executed. After the handler has returned, the timer may enter the
59 //! handler. A timer in the **started** or **running** state may be **canceled**
60 //! by the `cancel` operation. A timer that is cancelled enters the **stopped**
63 //! A `cancel` or `restart` operation on a timer in the **running** state takes
64 //! effect after the handler has returned and the timer has transitioned
67 //! A `restart` operation on a timer in the **stopped** state is equivalent to a
71 //! issue the `start` operation while the timer is in the **started** state. In
76 //! ## Using an intrusive timer living in a [`Box`]
117 //! timer: HrTimer<Self>,
124 //! timer <- HrTimer::new(),
134 //! pr_info!("Timer called\n");
149 //! mode: RelativeMode<Monotonic>, field: self.timer
165 //! ## Using an intrusive timer in an [`Arc`]
189 //! timer: HrTimer<Self>,
199 //! timer <- HrTimer::new(),
213 //! pr_info!("Timer called\n");
228 //! mode: RelativeMode<Monotonic>, field: self.timer
243 //! ## Using a stack-based timer
266 //! timer: HrTimer<Self>,
276 //! timer <- HrTimer::new(),
287 //! pr_info!("Timer called\n");
298 //! mode: RelativeMode<Monotonic>, field: self.timer
313 //! ## Using a mutable stack-based timer
355 //! timer: HrTimer<Self>,
362 //! timer <- HrTimer::new(),
372 //! pr_info!("Timer called\n");
387 //! mode: RelativeMode<Monotonic>, field: self.timer
416 /// A timer backed by a C `struct hrtimer`.
420 /// * `self.timer` is initialized by `bindings::hrtimer_setup`.
425 timer: Opaque<bindings::hrtimer>,
433 // SAFETY: Timer operations are locked on the C side, so it is safe to operate
434 // on a timer from multiple threads.
438 /// Return an initializer for a new timer instance.
445 // INVARIANT: We initialize `timer` with `hrtimer_setup` below.
446 timer <- Opaque::ffi_init(move |place: *mut bindings::hrtimer| {
472 // SAFETY: The field projection to `timer` does not go out of bounds,
475 unsafe { Opaque::cast_into(core::ptr::addr_of!((*this).timer)) }
478 /// Cancel an initialized and potentially running timer.
480 /// If the timer handler is running, this function will block until the
483 /// Note that the timer might be started by a concurrent start operation. If
484 /// so, the timer might not be in the **stopped** state when this function
489 /// returned when the timer was started.
508 /// Forward the timer expiry for a given timer pointer.
514 /// within the context of the timer callback.
528 /// Conditionally forward the timer.
530 /// If the timer expires after `now`, this function does nothing and returns 0. If the timer
531 /// expired at or before `now`, this function forwards the timer by `interval` until the timer
532 /// expires after `now` and then returns the number of times the timer was forwarded by
535 /// This function is mainly useful for timer types which can provide exclusive access to the
536 /// timer when the timer is not running. For forwarding the timer from within the timer callback
539 /// Returns the number of overruns that occurred as a result of the timer expiry change.
552 /// Conditionally forward the timer.
589 /// `Self` must be [`Sync`] because it is passed to timer callbacks in another
592 /// Starting a timer returns a [`HrTimerHandle`] that can be used to manipulate
593 /// the timer. Note that it is OK to call the start function repeatedly, and
595 /// exist. A timer can be manipulated through any of the handles, and a handle
596 /// may represent a cancelled timer.
598 /// The operational mode associated with this timer.
603 /// A handle representing a started or restarted timer.
605 /// If the timer is running or if the timer callback is executing when the
607 /// until the timer is stopped and the callback has completed.
613 /// Start the timer with expiry after `expires` time units. If the timer was
630 /// The operational mode associated with this timer.
635 /// A handle representing a running timer.
639 /// If the timer is running, or if the timer callback is executing when the
641 /// until the timer is stopped and the callback has completed.
644 /// Start the timer after `expires` time units. If the timer was already
649 /// Caller promises keep the timer structure alive until the timer is dead.
659 /// timer is dead and the timer handler is not running.
661 /// The operational mode associated with this timer.
666 /// Start the timer to run after `expires` time units and immediately
667 /// after call `f`. When `f` returns, the timer is cancelled.
674 // handle returned by [`UnsafeHrTimerPointer::start`] ensures that the timer is
690 // SAFETY: We drop the timer handle below before returning.
698 /// Implemented by [`HrTimerPointer`] implementers to give the C timer callback a
706 /// Callback to be called from C when timer fires.
711 /// to the `bindings::hrtimer` structure that was used to start the timer.
715 /// Implemented by structs that can be the target of a timer callback.
718 /// the timer expires.
721 /// Called by the timer logic when the timer fires.
731 /// A handle representing a potentially running timer.
733 /// More than one handle representing the same timer might exist.
737 /// When dropped, the timer represented by this handle must be cancelled, if it
738 /// is running. If the timer handler is running when the handle is dropped, the
744 /// Cancel the timer. If the timer is in the running state, block till the
747 /// Note that the timer might be started by a concurrent start operation. If
748 /// so, the timer might not be in the **stopped** state when this function
751 /// Returns `true` if the timer was running.
755 /// Implemented by structs that contain timer nodes.
757 /// Clients of the timer API would usually safely implement this trait by using
767 /// The operational mode associated with this timer.
811 /// Start the timer contained in the `Self` pointed to by `self_ptr`. If
817 /// - Caller must ensure that the pointee of `this` lives until the timer
836 /// Timer should not be restarted.
838 /// Timer should be restarted.
853 /// timer functions. The interpretation (absolute vs relative) depends on the
903 /// Timer that expires at a fixed point in time.
913 /// Timer that expires after a delay from now.
923 /// Timer with absolute expiration time, pinned to its current CPU.
932 /// Timer with relative expiration time, pinned to its current CPU.
941 /// Timer with absolute expiration, handled in soft irq context.
950 /// Timer with relative expiration, handled in soft irq context.
959 /// Timer with absolute expiration, pinned to CPU and handled in soft irq context.
968 /// Timer with absolute expiration, pinned to CPU and handled in soft irq context.
977 /// Timer with absolute expiration, handled in hard irq context.
986 /// Timer with relative expiration, handled in hard irq context.
995 /// Timer with absolute expiration, pinned to CPU and handled in hard irq context.
1004 /// Timer with relative expiration, pinned to CPU and handled in hard irq context.
1021 /// This type provides access to said methods from within a timer callback context.
1035 /// This function relies on the caller being within the context of a timer callback, so it must
1037 /// caller promises that `timer` points to a valid initialized instance of
1042 pub(crate) unsafe fn from_raw(timer: *mut HrTimer<T>) -> Self {
1043 // SAFETY: The caller guarantees `timer` is a valid pointer to an initialized
1045 // INVARIANT: Our safety contract ensures that we're within the context of a timer callback
1046 // and that `timer` points to a live instance of `HrTimer<T>`.
1047 Self(unsafe { NonNull::new_unchecked(timer) }, PhantomData)
1050 /// Conditionally forward the timer.
1056 // - We are guaranteed to be within the context of a timer callback by our type invariants
1061 /// Conditionally forward the timer.
1118 // `box` is a reserved keyword, so prefix with `t` for timer