Lines Matching defs:Atomic

3 //! Atomic primitives.
39 /// [`LKMM`][LKMM] atomic primitives. With the help of [`Atomic::from_ptr()`] and
40 /// [`Atomic::as_ptr()`], this provides a way to interact with [C-side atomic operations]
52 pub struct Atomic<T: AtomicType>(AtomicRepr<T::Repr>);
54 // SAFETY: `Atomic<T>` is safe to transfer between execution contexts because of the safety
56 unsafe impl<T: AtomicType> Send for Atomic<T> {}
58 // SAFETY: `Atomic<T>` is safe to share among execution contexts because all accesses are atomic.
59 unsafe impl<T: AtomicType> Sync for Atomic<T> {}
97 /// use kernel::sync::atomic::{AtomicType, Atomic, Relaxed};
113 /// let s = Atomic::new(State::Uninit);
155 impl<T: AtomicType> Atomic<T> {
179 /// Using [`Atomic::from_ptr()`] combined with [`Atomic::load()`] or [`Atomic::store()`] can
185 /// use kernel::sync::atomic::{Atomic, Relaxed, Release};
208 /// let a = unsafe { Atomic::from_ptr(foo_a_ptr) }.load(Relaxed);
215 /// unsafe { Atomic::from_ptr(foo_a_ptr) }.store(2, Release);
218 // CAST: `T` and `Atomic<T>` have the same size, alignment and bit validity.
220 // live long enough. It's safe to return a `&Atomic<T>` because function safety requirement
249 /// use kernel::sync::atomic::{Atomic, Relaxed};
251 /// let mut atomic_val = Atomic::new(0u32);
266 impl<T: AtomicType> Atomic<T>
275 /// use kernel::sync::atomic::{Atomic, Relaxed};
277 /// let x = Atomic::new(42i32);
281 /// let x = Atomic::new(42i64);
305 /// use kernel::sync::atomic::{Atomic, Relaxed};
307 /// let x = Atomic::new(42i32);
329 impl<T: AtomicType + core::fmt::Debug> core::fmt::Debug for Atomic<T>
338 impl<T: AtomicType> Atomic<T>
342 /// Atomic exchange.
349 /// use kernel::sync::atomic::{Atomic, Acquire, Relaxed};
351 /// let x = Atomic::new(42);
376 /// Atomic compare and exchange.
393 /// use kernel::sync::atomic::{Atomic, Full, Relaxed};
395 /// let x = Atomic::new(42);
467 /// Atomic compare and exchange and returns whether the operation succeeds.
472 /// "Compare" and "Ordering" part are the same as [`Atomic::cmpxchg()`].
504 impl<T: AtomicType> Atomic<T>
508 /// Atomic add.
515 /// use kernel::sync::atomic::{Atomic, Relaxed};
517 /// let x = Atomic::new(42);
537 /// Atomic fetch and add.
545 /// use kernel::sync::atomic::{Atomic, Acquire, Full, Relaxed};
547 /// let x = Atomic::new(42);
552 /// let x = Atomic::new(42);
579 /// Atomic fetch and subtract.
587 /// use kernel::sync::atomic::{Atomic, Acquire, Full, Relaxed};
589 /// let x = Atomic::new(42);
594 /// let x = Atomic::new(42);
670 /// [`AtomicFlag`] is generally preferable to [`Atomic<bool>`] when you need read-modify-write
671 /// (RMW) operations (e.g. [`Atomic::xchg()`]/[`Atomic::cmpxchg()`]) or when [`Atomic<bool>`] does
673 /// RMW operations, RMW operations on [`Atomic<bool>`] are slower.
675 /// If you only use [`Atomic::load()`]/[`Atomic::store()`], [`Atomic<bool>`] is fine.
687 pub struct AtomicFlag(Atomic<Flag>);
693 Self(Atomic::new(Flag::new(b)))
748 /// Atomic load over raw pointers.
750 /// This function provides a short-cut of `Atomic::from_ptr().load(..)`, and can be used to work
772 unsafe { Atomic::from_ptr(ptr) }.load(o)
775 /// Atomic store over raw pointers.
777 /// This function provides a short-cut of `Atomic::from_ptr().load(..)`, and can be used to work
799 unsafe { Atomic::from_ptr(ptr) }.store(v, o);
802 /// Atomic exchange over raw pointers.
804 /// This function provides a short-cut of `Atomic::from_ptr().xchg(..)`, and can be used to work
823 unsafe { Atomic::from_ptr(ptr) }.xchg(new, o)
826 /// Atomic compare and exchange over raw pointers.
828 /// This function provides a short-cut of `Atomic::from_ptr().cmpxchg(..)`, and can be used to work
849 unsafe { Atomic::from_ptr(ptr) }.cmpxchg(old, new, o)