* [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
* Re: [PATCH v1] rust: time: Add missing hrtimer example
2025-12-11 21:36 ` [PATCH v1] rust: time: Add missing hrtimer example FUJITA Tomonori
@ 2025-12-11 23:01 ` Andreas Hindborg
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Hindborg @ 2025-12-11 23:01 UTC (permalink / raw)
To: FUJITA Tomonori, ojeda
Cc: aliceryhl, anna-maria, bjorn3_gh, boqun.feng, dakr, frederic,
gary, jstultz, lossin, lyude, sboyd, tglx, tmgross,
rust-for-linux
"FUJITA Tomonori" <fujita.tomonori@gmail.com> writes:
> 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>
Thanks for producing the example.
I have examples for all of hrtimer sitting in my queue. We dropped them
from the original hrtimer series due to missing atomics at the time.
I'll be sure to send them soon.
Best regards,
Andreas Hindborg
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-11 23:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <vwF1DgikCzOFxKOUW--87jAok307D0NdFE8P-ptynDYfy5hV8Ucjr-xB2C8zXHzIcT4lPV4vhaL6YhKylxm3SQ==@protonmail.internalid>
2025-12-11 21:36 ` [PATCH v1] rust: time: Add missing hrtimer example FUJITA Tomonori
2025-12-11 23:01 ` Andreas Hindborg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).