rust: sync: atomic: Add example for Atomic::get_mut
Subsystems (3)
PATCH 1/1 rust: sync: atomic: Add example for Atomic::get_mut
From: FUJITA Tomonori <[email protected]>
Add an example for Atomic::get_mut(). No functional change.
Signed-off-by FUJITA Tomonori <[email protected]>
--- rust/kernel/sync/atomic.rs | 11 +++++++++++ 1 file changed, 11 insertions(+)
rust/kernel/sync/atomic.rs +11 -0
@@ -235,6 +235,17 @@ pub const fn as_ptr(&self) -> *mut 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
base-commit: 6583920e15fc567109e1c64ca58c917f52f40736
Signature · 1 line
2.43.0
Quoted 5 lines · FUJITA Tomonori
From: FUJITA Tomonori <[email protected]>
Add an example for
Atomic::get_mut(). No functional change.Signed-off-by FUJITA Tomonori <[email protected]>
Reviewed-by Gary Guo <[email protected]>
Quoted 3 lines
--- rust/kernel/sync/atomic.rs | 11 +++++++++++ 1 file changed, 11 insertions(+)
Quoted 5 lines · FUJITA Tomonori
From: FUJITA Tomonori <[email protected]>
Add an example for
Atomic::get_mut(). No functional change.Signed-off-by FUJITA Tomonori <[email protected]>
Reviewed-by Alice Ryhl <[email protected]>
Quoted 5 lines · FUJITA Tomonori
From: FUJITA Tomonori <[email protected]>
Add an example for
Atomic::get_mut(). No functional change.Signed-off-by FUJITA Tomonori <[email protected]>
Queued! Thank you all!
Regards,
Boqun