From: FUJITA Tomonori Date: Tue, 3 Mar 2026 20:16:50 +0000 (-0800) Subject: rust: sync: atomic: Add example for Atomic::get_mut() X-Git-Tag: v7.1-rc1~199^2~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bebf7bdc62537b9ef4700c6402f1c2aa206a9b50;p=thirdparty%2Fkernel%2Flinux.git rust: sync: atomic: Add example for Atomic::get_mut() Add an example for Atomic::get_mut(). No functional change. Signed-off-by: FUJITA Tomonori Signed-off-by: Boqun Feng Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Alice Ryhl Reviewed-by: Gary Guo Link: https://patch.msgid.link/20260128123313.3850604-1-tomo@aliasing.net Link: https://patch.msgid.link/20260303201701.12204-3-boqun@kernel.org --- diff --git a/rust/kernel/sync/atomic.rs b/rust/kernel/sync/atomic.rs index 296b25e83bbb9..e262b0cb53ae2 100644 --- a/rust/kernel/sync/atomic.rs +++ b/rust/kernel/sync/atomic.rs @@ -232,6 +232,17 @@ impl Atomic { /// 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