Function sparse_mmap::try_compare_exchange
source · pub unsafe fn try_compare_exchange<T: AsBytes + FromBytes>(
dest: *mut T,
current: T,
new: T,
) -> Result<Result<T, T>, MemoryError>
Expand description
Atomically swaps the value at dest
with new
when *dest
is current
,
using a sequentially-consistent memory ordering.
Returns Ok(Ok(new))
if the swap was successful, Ok(Err(*dest))
if the
swap failed, or Err(MemoryError::AccessViolation)
if the swap could not be
attempted due to an access violation.
Panics if the size is not 1, 2, 4, or 8 bytes.
§Safety
This routine is safe to use if the memory pointed to by dest
is being
concurrently mutated.
WARNING: This routine should only be used when you know that dest
is
valid, reserved addresses but you do not know if they are mapped with the
appropriate protection. For example, this routine is useful if dest
is a
sparse mapping where some pages are mapped with PAGE_NOACCESS/PROT_NONE, and
some are mapped with PAGE_READWRITE/PROT_WRITE.