std.atomics
atomic ops; rmw returns the previous value; helpers are seq-cst
Relaxed
Section titled “Relaxed”pub Relaxed :: 0orderings for core::atomic_*; must be comptime-known
Acquire
Section titled “Acquire”pub Acquire :: 1Release
Section titled “Release”pub Release :: 2AcqRel
Section titled “AcqRel”pub AcqRel :: 3SeqCst
Section titled “SeqCst”pub SeqCst :: 4Native
Section titled “Native”pub Native :: constraint($T)int, float, bool or pointer, at most word-sized
Numeric
Section titled “Numeric”pub Numeric :: constraint($T)int or float, for add/sub/mul/div
Integer
Section titled “Integer”pub Integer :: constraint($T)int only: bitwise, shifts, min/max
Boolean
Section titled “Boolean”pub Boolean :: constraint($T)for flag helpers
pub load :: fn($T: Native, p: *T) -> Tpub store :: fn($T: Native, p: *T, v: T)load_acquire
Section titled “load_acquire”pub load_acquire :: fn($T: Native, p: *T) -> Tacquire load; pairs with store_release
store_release
Section titled “store_release”pub store_release :: fn($T: Native, p: *T, v: T)release store; pairs with load_acquire
pub swap :: fn($T: Native, p: *T, v: T) -> Treturns the previous value
compare_exchange
Section titled “compare_exchange”pub compare_exchange :: fn($T: Native, p: *T, expected: T, desired: T) -> booltrue if *p was expected and is now desired
compare_exchange_value
Section titled “compare_exchange_value”pub compare_exchange_value :: fn($T: Native, p: *T, expected: T, desired: T) -> Treturns the observed value (== expected on success)
fetch_add
Section titled “fetch_add”pub fetch_add :: fn($T: Numeric, p: *T, v: T) -> Tnative for ints and floats
fetch_sub
Section titled “fetch_sub”pub fetch_sub :: fn($T: Numeric, p: *T, v: T) -> Tfetch_mul
Section titled “fetch_mul”pub fetch_mul :: fn($T: Numeric, p: *T, v: T) -> Tno hardware atomic; cas retry loop
fetch_div
Section titled “fetch_div”pub fetch_div :: fn($T: Numeric, p: *T, v: T) -> Tfetch_max
Section titled “fetch_max”pub fetch_max :: fn($T: Integer, p: *T, v: T) -> Tmin / max (ints; signedness from T)
fetch_min
Section titled “fetch_min”pub fetch_min :: fn($T: Integer, p: *T, v: T) -> Tfetch_and
Section titled “fetch_and”pub fetch_and :: fn($T: Integer, p: *T, v: T) -> Tbitwise (ints; returns the previous value)
fetch_or
Section titled “fetch_or”pub fetch_or :: fn($T: Integer, p: *T, v: T) -> Tfetch_xor
Section titled “fetch_xor”pub fetch_xor :: fn($T: Integer, p: *T, v: T) -> Tfetch_nand
Section titled “fetch_nand”pub fetch_nand :: fn($T: Integer, p: *T, v: T) -> Tfetch_shl
Section titled “fetch_shl”pub fetch_shl :: fn($T: Integer, p: *T, bits: T) -> Tno hardware atomic; cas retry loops
fetch_shr
Section titled “fetch_shr”pub fetch_shr :: fn($T: Integer, p: *T, bits: T) -> Tpub fence :: fn()seq-cst fence
fence_acquire
Section titled “fence_acquire”pub fence_acquire :: fn()nothing after it moves before it
fence_release
Section titled “fence_release”pub fence_release :: fn()nothing before it moves after it
is_set
Section titled “is_set”pub is_set :: fn(flag: *u32) -> booltest_and_set
Section titled “test_and_set”pub test_and_set :: fn(flag: *u32) -> boolsets to 1; returns whether it was already set
pub clear :: fn(flag: *u32)wait_until_set
Section titled “wait_until_set”pub wait_until_set :: fn(flag: *u32)busy-waits
wait_until_eq
Section titled “wait_until_eq”pub wait_until_eq :: fn(flag: *u32, value: u32)busy-waits until *flag == value
spin_lock
Section titled “spin_lock”pub spin_lock :: fn(lock: *u32)spins on test_and_set until it wins 0 -> 1
spin_unlock
Section titled “spin_unlock”pub spin_unlock :: fn(lock: *u32)Atomic
Section titled “Atomic”pub Atomic :: struct($T: Native) { value: T,}typed atomic cell; methods skip the Integer/Numeric checks the free fns do
Atomic.make
Section titled “Atomic.make”pub make :: fn(v: T) -> SelfAtomic.get
Section titled “Atomic.get”pub get :: fn(self: *Self) -> TAtomic.set
Section titled “Atomic.set”pub set :: fn(self: *Self, v: T)Atomic.get_acquire
Section titled “Atomic.get_acquire”pub get_acquire :: fn(self: *Self) -> TAtomic.set_release
Section titled “Atomic.set_release”pub set_release :: fn(self: *Self, v: T)Atomic.exchange
Section titled “Atomic.exchange”pub exchange :: fn(self: *Self, v: T) -> TAtomic.cas
Section titled “Atomic.cas”pub cas :: fn(self: *Self, expected: T, desired: T) -> boolcas: bool and observed-value variants
Atomic.cas_value
Section titled “Atomic.cas_value”pub cas_value :: fn(self: *Self, expected: T, desired: T) -> TAtomic.add
Section titled “Atomic.add”pub add :: fn(self: *Self, v: T) -> Tarithmetic; returns the previous value
Atomic.sub
Section titled “Atomic.sub”pub sub :: fn(self: *Self, v: T) -> TAtomic.mul
Section titled “Atomic.mul”pub mul :: fn(self: *Self, v: T) -> TAtomic.div
Section titled “Atomic.div”pub div :: fn(self: *Self, v: T) -> TAtomic.max
Section titled “Atomic.max”pub max :: fn(self: *Self, v: T) -> Tmin / max + bitwise; returns the previous value
Atomic.min
Section titled “Atomic.min”pub min :: fn(self: *Self, v: T) -> TAtomic.and
Section titled “Atomic.and”pub and :: fn(self: *Self, v: T) -> TAtomic.or
Section titled “Atomic.or”pub or :: fn(self: *Self, v: T) -> TAtomic.xor
Section titled “Atomic.xor”pub xor :: fn(self: *Self, v: T) -> TAtomic.nand
Section titled “Atomic.nand”pub nand :: fn(self: *Self, v: T) -> T