rasa/atomic

Atomic integers backed by Erlang’s atomics. Each Atomic is a single signed 64-bit integer. Atomics use atomic hardware instructions without software locking.

Types

A single atomic integer.

pub opaque type Atomic

Values

pub fn add(atomic: Atomic, value: Int) -> Nil

Adds the given value to the atomic.

pub fn add_get(atomic: Atomic, value: Int) -> Int

Atomically adds the given value to the atomic and returns the result.

pub fn compare_exchange(
  atomic: Atomic,
  expected: Int,
  desired: Int,
) -> Result(Nil, Int)

Atomically compares the atomic with expected, and if equal, sets it to desired. Returns Ok(Nil) if the swap succeeded, or Error(actual) with the actual value if it did not match expected.

pub fn exchange(atomic: Atomic, value: Int) -> Int

Atomically replaces the value of the atomic with the given value and returns the previous value.

pub fn get(atomic: Atomic) -> Int

Returns the current value of the atomic.

pub fn new() -> Atomic

Creates a new Atomic initialized to 0.

pub fn put(atomic: Atomic, value: Int) -> Nil

Sets the atomic to the given value.

pub fn sub(atomic: Atomic, value: Int) -> Nil

Subtracts the given value from the atomic.

pub fn sub_get(atomic: Atomic, value: Int) -> Int

Atomically subtracts the given value from the atomic and returns the result.

Search Document