pub struct AtomicMode(/* private fields */);Expand description
A wrapper around Mode which can be safely shared between threads.
This type uses an AtomicUsize to store the enum value.
Implementations§
Source§impl AtomicMode
impl AtomicMode
Sourcepub const fn new(v: Mode) -> AtomicMode
pub const fn new(v: Mode) -> AtomicMode
Creates a new atomic Mode.
Sourcepub fn into_inner(self) -> Mode
pub fn into_inner(self) -> Mode
Consumes the atomic and returns the contained value.
This is safe because passing self by value guarantees that no other threads are concurrently accessing the atomic data.
Sourcepub fn set(&mut self, v: Mode)
pub fn set(&mut self, v: Mode)
Sets the value of the atomic without performing an atomic operation.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
Sourcepub fn get(&mut self) -> Mode
pub fn get(&mut self) -> Mode
Gets the value of the atomic without performing an atomic operation.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
Sourcepub fn swap_mut(&mut self, v: Mode) -> Mode
pub fn swap_mut(&mut self, v: Mode) -> Mode
Stores a value into the atomic, returning the previous value, without performing an atomic operation.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
Source§impl AtomicMode
impl AtomicMode
Sourcepub fn swap(&self, val: Mode, order: Ordering) -> Mode
pub fn swap(&self, val: Mode, order: Ordering) -> Mode
Stores a value into the atomic, returning the previous value.
swap takes an Ordering argument which describes the memory ordering of this operation.
All ordering modes are possible. Note that using Acquire makes the store part of this operation Relaxed,
and using Release makes the load part Relaxed.
Sourcepub fn compare_and_swap(
&self,
current: Mode,
new: Mode,
order: Ordering,
) -> Mode
👎Deprecated: Use compare_exchange or compare_exchange_weak instead
pub fn compare_and_swap( &self, current: Mode, new: Mode, order: Ordering, ) -> Mode
compare_exchange or compare_exchange_weak insteadStores a value into the atomic if the current value is the same as the current value.
The return value is always the previous value. If it is equal to current, then the value was updated.
compare_and_swap also takes an Ordering argument which describes the memory ordering of this operation.
Notice that even when using AcqRel, the operation might fail and hence just perform an Acquire load, but
not have Release semantics. Using Acquire makes the store part of this operation Relaxed if it happens,
and using Release makes the load part Relaxed.
Sourcepub fn compare_exchange(
&self,
current: Mode,
new: Mode,
success: Ordering,
failure: Ordering,
) -> Result<Mode, Mode>
pub fn compare_exchange( &self, current: Mode, new: Mode, success: Ordering, failure: Ordering, ) -> Result<Mode, Mode>
Stores a value into the atomic if the current value is the same as the current value.
The return value is a result indicating whether the new value was written and containing the previous value.
On success this value is guaranteed to be equal to current.
compare_exchange takes two Ordering arguments to describe the memory ordering of this operation. The first
describes the required ordering if the operation succeeds while the second describes the required ordering when
the operation fails. Using Acquire as success ordering makes the store part of this operation Relaxed, and
using Release makes the successful load Relaxed. The failure ordering can only be SeqCst, Acquire or
Relaxed and must be equivalent to or weaker than the success ordering.
Sourcepub fn compare_exchange_weak(
&self,
current: Mode,
new: Mode,
success: Ordering,
failure: Ordering,
) -> Result<Mode, Mode>
pub fn compare_exchange_weak( &self, current: Mode, new: Mode, success: Ordering, failure: Ordering, ) -> Result<Mode, Mode>
Stores a value into the atomic if the current value is the same as the current value.
Unlike compare_exchange, this function is allowed to spuriously fail even when the comparison succeeds,
which can result in more efficient code on some platforms. The return value is a result indicating whether
the new value was written and containing the previous value.
compare_exchange_weak takes two Ordering arguments to describe the memory ordering of this operation.
The first describes the required ordering if the operation succeeds while the second describes the required
ordering when the operation fails. Using Acquire as success ordering makes the store part of this operation
Relaxed, and using Release makes the successful load Relaxed. The failure ordering can only be SeqCst,
Acquire or Relaxed and must be equivalent to or weaker than the success ordering.