No matching definitions.

tur/atomic

stdlib/atomic.tur

atomic load/store/add/sub/swap/CAS on 64-bit integers.

Thread-safe integer operations using C11 _Atomic semantics.

Since: Phase T19

defopaque

AtomicCell

(defopaque AtomicCell [A] :ptr<void>)
defn

atomic-new

(atomic-new [A])

allocate a heap-based atomic int64 cell initialised to init.

initinitial integer value stored in the cell

An AtomicCell handle to the new atomic cell.

(def a (atomic-new 0))  ; => AtomicCell holding 0

Since: Phase T19

defn

atomic-load

(atomic-load [A])

atomically read the current value of the cell.

patomic cell pointer from atomic-new

The current int64 value (sequentially-consistent load).

(atomic-load a)  ; => 0

Since: Phase T19

defn

atomic-store!

(atomic-store! [A])

atomically write v into the cell.

patomic cell pointer from atomic-new
vnew value to store

Since: Phase T19

defn

atomic-add!

(atomic-add! [p :(AtomicCell int) delta :int] :int)

atomically add delta and return the old value.

patomic cell pointer from atomic-new
deltaamount to add (may be negative)

The value of the cell before the addition.

(atomic-add! a 5)  ; => old value; cell now holds old+5

Since: Phase T19

defn

atomic-sub!

(atomic-sub! [p :(AtomicCell int) delta :int] :int)

atomically subtract delta and return the old value.

patomic cell pointer from atomic-new
deltaamount to subtract

The value of the cell before the subtraction.

Since: Phase T19

defn

atomic-swap!

(atomic-swap! [A])

atomically replace the cell value with new-val and return the old value.

patomic cell pointer from atomic-new
new-valvalue to store

The value of the cell before the swap.

(atomic-swap! a 99)  ; => old value; cell now holds 99

Since: Phase T19

defn

atomic-cas!

(atomic-cas! [A])

compare-and-swap: if cell == expected, set to desired and return true.

patomic cell pointer from atomic-new
expectedvalue to compare against
desiredvalue to store if comparison succeeds

true if the swap occurred, false if the current value differed from expected.

(atomic-cas! a 0 1)  ; => true when cell held 0; cell now holds 1

Since: Phase T19

defn

atomic-free

(atomic-free [A])

free an atomic cell allocated by atomic-new.

patomic cell pointer from atomic-new

Since: Phase T19