fn Atomic(comptime T: type) type
Functions
inline fn compareAndSwap(self: *Self, compare: T, exchange: T, comptime success: Ordering, comptime failure: Ordering) ?T
No documentation provided.
inline fn fence(self: *Self, comptime ordering: Ordering) void
Perform an atomic fence which uses the atomic value as a hint for the modificati…
Perform an atomic fence which uses the atomic value as a hint for the modification order. Use this when you want to imply a fence on an atomic variable without necessarily performing a memory access.
Example:
const RefCount = struct { count: Atomic(usize), dropFn: *const fn(*RefCount) void, fn ref(self: *RefCount) void { _ = self.count.fetchAdd(1, .Monotonic); // no ordering necessary, just updating a counter } fn unref(self: *RefCount) void { // Release ensures code before unref() happens-before the count is decremented as dropFn could be called by then. if (self.count.fetchSub(1, .Release)) { // Acquire ensures count decrement and code before previous unrefs()s happens-before we call dropFn below. // NOTE: another alternative is to use .AcqRel on the fetchSub count decrement but it's extra barrier in possibly hot path. self.count.fence(.Acquire); (self.dropFn)(self); } } };
inline fn loadUnchecked(self: Self) T
Non-atomically load from the atomic value without synchronization. Care must be…
Non-atomically load from the atomic value without synchronization. Care must be taken to avoid data-races when interacting with other atomic operations.
inline fn storeUnchecked(self: *Self, value: T) void
Non-atomically store to the atomic value without synchronization. Care must be …
Non-atomically store to the atomic value without synchronization. Care must be taken to avoid data-races when interacting with other atomic operations.
inline fn tryCompareAndSwap(self: *Self, compare: T, exchange: T, comptime success: Ordering, comptime failure: Ordering) ?T
No documentation provided.