* [PATCH v1] rust: time: Add missing hrtimer example
@ 2025-12-11 21:36 ` FUJITA Tomonori
2025-12-11 23:01 ` Andreas Hindborg
0 siblings, 1 reply; 2+ messages in thread
From: FUJITA Tomonori @ 2025-12-11 21:36 UTC (permalink / raw)
To: a.hindborg, ojeda
Cc: aliceryhl, anna-maria, bjorn3_gh, boqun.feng, dakr, frederic,
gary, jstultz, lossin, lyude, sboyd, tglx, tmgross,
rust-for-linux
The impl_has_hr_timer macro docs says that "see module documentation
for an example" but there wasn't one. This adds an example usage of
the macro.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
rust/kernel/time/hrtimer.rs | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
index 856d2d929a00..be0cae7a7da1 100644
--- a/rust/kernel/time/hrtimer.rs
+++ b/rust/kernel/time/hrtimer.rs
@@ -66,6 +66,41 @@
//!
//! A `restart` operation on a timer in the **stopped** state is equivalent to a
//! `start` operation.
+//!
+//! # Examples
+//!
+//! ```
+//! use kernel::sync::{Arc, ArcBorrow};
+//! use kernel::time::hrtimer::{
+//! AbsoluteMode, HrTimer, HrTimerCallback, HrTimerCallbackContext, HrTimerRestart,
+//! };
+//! use kernel::{impl_has_hr_timer, prelude::*};
+//!
+//! #[pin_data]
+//! struct MyDriver {
+//! #[pin]
+//! timer: HrTimer<Self>,
+//! }
+//!
+//! impl HrTimerCallback for MyDriver {
+//! type Pointer<'a> = Arc<Self>;
+//!
+//! fn run<'a>(
+//! _this: ArcBorrow<'a, MyDriver>,
+//! _ctx: HrTimerCallbackContext<'a, Self>,
+//! ) -> HrTimerRestart {
+//! // Timer callback logic here
+//! HrTimerRestart::NoRestart
+//! }
+//! }
+//!
+//! impl_has_hr_timer! {
+//! impl HasHrTimer<Self> for MyDriver {
+//! mode : AbsoluteMode<kernel::time::Monotonic>,
+//! field : self.timer
+//! }
+//! }
+//! ```
use super::{ClockSource, Delta, Instant};
use crate::{prelude::*, types::Opaque};
base-commit: 0048fbb4011ec55c32d3148b2cda56433f273375
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread