Skip to main content

atomic_store_u32_release

Function atomic_store_u32_release 

Source
pub unsafe fn atomic_store_u32_release(addr: usize, value: u32)
Expand description

This performs an atomic store-release of a 32-bit value to addr. Use this if you have a u32 or your struct is align(4).

Rust’s memory model defines how atomics work across threads, but doesn’t account for the way Starnix handles access across mutually distrusting address spaces. This Seqlock is intended to be mapped and read by different address spaces. Rust’s guarantees do not apply and reading across these address spaces is undefined behavior. Theoretically the Rust compiler could determine that the atomic is never read from within the process and optimize out the store. We work around this by directly including the assembly an atomic would generate to prevent the compiler from “helpfully” optimizing it away.

§Safety

  1. The caller must ensure addr is valid and 4-byte aligned. The addr must be writable by the current process. You can check: if std::ptr::write_volatile() is able to write successfully to this addr, then this should work too.
  2. The caller must ensure that no other non-atomic operations are occurring on this memory address simultaneously.