fn Atomic(comptime T: type) type

Parameters

T: type,

Fields

value: T,

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);
        }
    }
};
fn init(value: T) Self

No documentation provided.

inline fn load(self: *const Self, comptime ordering: Ordering) T

No documentation provided.

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 store(self: *Self, value: T, comptime ordering: Ordering) void

No documentation provided.

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 swap(self: *Self, value: T, comptime ordering: Ordering) T

No documentation provided.

inline fn tryCompareAndSwap(self: *Self, compare: T, exchange: T, comptime success: Ordering, comptime failure: Ordering) ?T

No documentation provided.