summaryrefslogtreecommitdiff
path: root/rust/kernel/sync
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@gmail.com>2026-03-03 12:16:50 -0800
committerPeter Zijlstra <peterz@infradead.org>2026-03-08 11:06:48 +0100
commitbebf7bdc62537b9ef4700c6402f1c2aa206a9b50 (patch)
tree2857afabe6033a93e05fd03be2885ce502858ff3 /rust/kernel/sync
parent4a5dc632e0b603ec1cbbf87b78de86b4b6359cff (diff)
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@gmail.com> Signed-off-by: Boqun Feng <boqun@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260128123313.3850604-1-tomo@aliasing.net Link: https://patch.msgid.link/20260303201701.12204-3-boqun@kernel.org
Diffstat (limited to 'rust/kernel/sync')
-rw-r--r--rust/kernel/sync/atomic.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/rust/kernel/sync/atomic.rs b/rust/kernel/sync/atomic.rs
index 296b25e83bbb..e262b0cb53ae 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