rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
To: a.hindborg@kernel.org, ojeda@kernel.org
Cc: aliceryhl@google.com, anna-maria@linutronix.de,
	bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org,
	frederic@kernel.org, gary@garyguo.net, jstultz@google.com,
	lossin@kernel.org, lyude@redhat.com, sboyd@kernel.org,
	tglx@linutronix.de, tmgross@umich.edu,
	rust-for-linux@vger.kernel.org
Subject: [PATCH v1] rust: time: Add missing hrtimer example
Date: Fri, 12 Dec 2025 06:36:08 +0900	[thread overview]
Message-ID: <20251211213608.1302051-1-fujita.tomonori@gmail.com> (raw)

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


             reply	other threads:[~2025-12-11 21:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <vwF1DgikCzOFxKOUW--87jAok307D0NdFE8P-ptynDYfy5hV8Ucjr-xB2C8zXHzIcT4lPV4vhaL6YhKylxm3SQ==@protonmail.internalid>
2025-12-11 21:36 ` FUJITA Tomonori [this message]
2025-12-11 23:01   ` [PATCH v1] rust: time: Add missing hrtimer example Andreas Hindborg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251211213608.1302051-1-fujita.tomonori@gmail.com \
    --to=fujita.tomonori@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=anna-maria@linutronix.de \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=frederic@kernel.org \
    --cc=gary@garyguo.net \
    --cc=jstultz@google.com \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).