pub trait AtomicCompareExchange: AtomicLoad + AtomicStore {
// Provided methods
unsafe fn atomic_compare_exchange(
dst: *mut MaybeUninit<Self>,
current: MaybeUninit<Self>,
new: MaybeUninit<Self>,
success: Ordering,
failure: Ordering,
) -> (MaybeUninit<Self>, bool) { ... }
unsafe fn atomic_compare_exchange_weak(
dst: *mut MaybeUninit<Self>,
current: MaybeUninit<Self>,
new: MaybeUninit<Self>,
success: Ordering,
failure: Ordering,
) -> (MaybeUninit<Self>, bool) { ... }
}Expand description
Atomic compare and exchange.
This trait is sealed and cannot be implemented for types outside of atomic-maybe-uninit.
Provided Methods§
Sourceunsafe fn atomic_compare_exchange(
dst: *mut MaybeUninit<Self>,
current: MaybeUninit<Self>,
new: MaybeUninit<Self>,
success: Ordering,
failure: Ordering,
) -> (MaybeUninit<Self>, bool)
unsafe fn atomic_compare_exchange( dst: *mut MaybeUninit<Self>, current: MaybeUninit<Self>, new: MaybeUninit<Self>, success: Ordering, failure: Ordering, ) -> (MaybeUninit<Self>, bool)
Stores a value into dst if the current value is the same as
the current value. Here, “the same” is determined using byte-wise
equality, not PartialEq.
The return value is a tuple of the previous value and the result indicating whether the new
value was written and containing the previous value. On success, the returned value is
guaranteed to be equal to the value at current.
atomic_compare_exchange takes two Ordering arguments to describe the memory
ordering of this operation. success describes the required ordering for the
read-modify-write operation that takes place if the comparison with current succeeds.
failure describes the required ordering for the load operation that takes place when
the comparison 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.
§Safety
Behavior is undefined if any of the following conditions are violated:
dstmust be valid for both reads and writes.dstmust be aligned tosize_of::<MaybeUninit<T>>()(note that on some platforms this can be bigger thanalign_of::<MaybeUninit<T>>()).successmust beSeqCst,AcqRel,Acquire,Release, orRelaxed.failuremust beSeqCst,Acquire, orRelaxed.- You must adhere to the Memory model for atomic accesses. In particular, it is not allowed to mix conflicting atomic and non-atomic accesses, or atomic accesses of different sizes, without synchronization.
§Notes
Comparison of two values containing uninitialized bytes may fail even if they are equivalent as Rust’s type, because values can be byte-wise inequal even when they are equal as Rust values.
See AtomicMaybeUninit::compare_exchange for details.
Sourceunsafe fn atomic_compare_exchange_weak(
dst: *mut MaybeUninit<Self>,
current: MaybeUninit<Self>,
new: MaybeUninit<Self>,
success: Ordering,
failure: Ordering,
) -> (MaybeUninit<Self>, bool)
unsafe fn atomic_compare_exchange_weak( dst: *mut MaybeUninit<Self>, current: MaybeUninit<Self>, new: MaybeUninit<Self>, success: Ordering, failure: Ordering, ) -> (MaybeUninit<Self>, bool)
Stores a value into dst if the current value is the same as
the current value. Here, “the same” is determined using byte-wise
equality, not PartialEq.
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 tuple of the previous value and the result indicating whether the new value was written and containing the previous value.
atomic_compare_exchange_weak takes two Ordering arguments to describe the memory
ordering of this operation. success describes the required ordering for the
read-modify-write operation that takes place if the comparison with current succeeds.
failure describes the required ordering for the load operation that takes place when
the comparison 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.
§Safety
Behavior is undefined if any of the following conditions are violated:
dstmust be valid for both reads and writes.dstmust be aligned tosize_of::<MaybeUninit<T>>()(note that on some platforms this can be bigger thanalign_of::<MaybeUninit<T>>()).successmust beSeqCst,AcqRel,Acquire,Release, orRelaxed.failuremust beSeqCst,Acquire, orRelaxed.- You must adhere to the Memory model for atomic accesses. In particular, it is not allowed to mix conflicting atomic and non-atomic accesses, or atomic accesses of different sizes, without synchronization.
§Notes
Comparison of two values containing uninitialized bytes may fail even if they are equivalent as Rust’s type, because values can be byte-wise inequal even when they are equal as Rust values.
See AtomicMaybeUninit::compare_exchange for details.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".