pub struct AtomicFlag(/* private fields */);Expand description
An atomic flag type intended to be backed by performance-optimal integer type.
The backing integer type is an implementation detail; it may vary by architecture and change in the future.
AtomicFlag is generally preferable to Atomic<bool> when you need read-modify-write
(RMW) operations (e.g. Atomic::xchg()/Atomic::cmpxchg()) or when Atomic<bool> does
not save memory due to padding. On some architectures that do not support byte-sized atomic
RMW operations, RMW operations on Atomic<bool> are slower.
If you only use Atomic::load()/Atomic::store(), Atomic<bool> is fine.
§Examples
use kernel::sync::atomic::{AtomicFlag, Relaxed};
let flag = AtomicFlag::new(false);
assert_eq!(false, flag.load(Relaxed));
flag.store(true, Relaxed);
assert_eq!(true, flag.load(Relaxed));Implementations§
Source§impl AtomicFlag
impl AtomicFlag
Sourcepub fn get_mut(&mut self) -> &mut bool
pub fn get_mut(&mut self) -> &mut bool
Returns a mutable reference to the underlying flag as a bool.
This is safe because the mutable reference of the atomic flag guarantees exclusive access.
§Examples
use kernel::sync::atomic::{AtomicFlag, Relaxed};
let mut atomic_flag = AtomicFlag::new(false);
assert_eq!(false, atomic_flag.load(Relaxed));
*atomic_flag.get_mut() = true;
assert_eq!(true, atomic_flag.load(Relaxed));Sourcepub fn load<Ordering: AcquireOrRelaxed>(&self, o: Ordering) -> bool
pub fn load<Ordering: AcquireOrRelaxed>(&self, o: Ordering) -> bool
Loads the value from the atomic flag.
Sourcepub fn store<Ordering: ReleaseOrRelaxed>(&self, v: bool, o: Ordering)
pub fn store<Ordering: ReleaseOrRelaxed>(&self, v: bool, o: Ordering)
Stores a value to the atomic flag.
Auto Trait Implementations§
impl !Freeze for AtomicFlag
impl !RefUnwindSafe for AtomicFlag
impl Send for AtomicFlag
impl Sync for AtomicFlag
impl Unpin for AtomicFlag
impl UnsafeUnpin for AtomicFlag
impl UnwindSafe for AtomicFlag
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
slot. Read more