Function sparse_mmap::try_compare_exchange_ref
source · pub unsafe fn try_compare_exchange_ref<T: AsBytes + FromBytes + ?Sized>(
dest: *mut u8,
current: &mut T,
new: &T,
) -> Result<bool, MemoryError>
Expand description
Atomically swaps the value at dest
with new
when *dest
is current
,
using a sequentially-consistent memory ordering.
Returns Ok(true)
if the swap was successful, Ok(false)
if the swap
failed (after updating current
), or Err(MemoryError::AccessViolation)
if
the swap could not be attempted due to an access violation.
Panics if current
and new
are not the same size or that 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.