Skip to contentSkip to conversation

rust: sync: atomic: Add example for Atomic::get_mut

PATCH Applied FUJITA Tomonori 4 participants 4 messages Jan 28 – Jan 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

---
 rust/kernel/sync/atomic.rs | 11 +++++++++++
 1 file changed, 11 insertions(+)
rust/kernel/sync/atomic.rs +11 -0
index 4aebeacb961a..d44550adb0d4 100644
@@ -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