Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

FUJITA Tomonori and committed by
Peter Zijlstra
bebf7bdc 4a5dc632

+11
+11
rust/kernel/sync/atomic.rs
··· 232 232 /// Returns a mutable reference to the underlying atomic `T`. 233 233 /// 234 234 /// This is safe because the mutable reference of the atomic `T` guarantees exclusive access. 235 + /// 236 + /// # Examples 237 + /// 238 + /// ``` 239 + /// use kernel::sync::atomic::{Atomic, Relaxed}; 240 + /// 241 + /// let mut atomic_val = Atomic::new(0u32); 242 + /// let val_mut = atomic_val.get_mut(); 243 + /// *val_mut = 101; 244 + /// assert_eq!(101, atomic_val.load(Relaxed)); 245 + /// ``` 235 246 pub fn get_mut(&mut self) -> &mut T { 236 247 // CAST: `T` and `T::Repr` has the same size and alignment per the safety requirement of 237 248 // `AtomicType`, and per the type invariants `self.0` is a valid `T`, therefore the casting