[tip: locking/core] rust: sync: atomic: Add example for Atomic::get_mut()
From: tip-bot2 for FUJITA Tomonori
Date: Mon Mar 09 2026 - 15:53:23 EST
The following commit has been merged into the locking/core branch of tip:
Commit-ID: bebf7bdc62537b9ef4700c6402f1c2aa206a9b50
Gitweb: https://git.kernel.org/tip/bebf7bdc62537b9ef4700c6402f1c2aa206a9b50
Author: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>
AuthorDate: Tue, 03 Mar 2026 12:16:50 -08:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Sun, 08 Mar 2026 11:06:48 +01:00
rust: sync: atomic: Add example for Atomic::get_mut()
Add an example for Atomic::get_mut(). No functional change.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>
Signed-off-by: Boqun Feng <boqun@xxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
Link: https://patch.msgid.link/20260128123313.3850604-1-tomo@xxxxxxxxxxxx
Link: https://patch.msgid.link/20260303201701.12204-3-boqun@xxxxxxxxxx
---
rust/kernel/sync/atomic.rs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/rust/kernel/sync/atomic.rs b/rust/kernel/sync/atomic.rs
index 296b25e..e262b0c 100644
--- a/rust/kernel/sync/atomic.rs
+++ b/rust/kernel/sync/atomic.rs
@@ -232,6 +232,17 @@ impl<T: AtomicType> Atomic<T> {
/// Returns a mutable reference to the underlying atomic `T`.
///
/// This is safe because the mutable reference of the atomic `T` guarantees exclusive access.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use kernel::sync::atomic::{Atomic, Relaxed};
+ ///
+ /// let mut atomic_val = Atomic::new(0u32);
+ /// let val_mut = atomic_val.get_mut();
+ /// *val_mut = 101;
+ /// assert_eq!(101, atomic_val.load(Relaxed));
+ /// ```
pub fn get_mut(&mut self) -> &mut T {
// CAST: `T` and `T::Repr` has the same size and alignment per the safety requirement of
// `AtomicType`, and per the type invariants `self.0` is a valid `T`, therefore the casting