]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: sync: atomic: Add example for Atomic::get_mut()
authorFUJITA Tomonori <fujita.tomonori@gmail.com>
Tue, 3 Mar 2026 20:16:50 +0000 (12:16 -0800)
committerPeter Zijlstra <peterz@infradead.org>
Sun, 8 Mar 2026 10:06:48 +0000 (11:06 +0100)
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
rust/kernel/sync/atomic.rs

index 296b25e83bbb95070b4c978b280527196bd5f829..e262b0cb53ae2ae6711b501646cd8b775fd92ba6 100644 (file)
@@ -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