No matching definitions.

tur/atomic

stdlib/atomic.tur

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

Since: Phase T19

defn

atomic-new

(atomic-new [init :int] :ptr<void>)

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

initinitial integer value stored in the cell

A :ptr<void> handle to the new atomic cell.

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

Since: Phase T19

defn

atomic-load

(atomic-load [p :ptr<void>] :int)

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! [p :ptr<void> v :int] :nil)

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 :ptr<void> 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 :ptr<void> 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! [p :ptr<void> new-val :int] :int)

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! [p :ptr<void> expected :int desired :int] :bool)

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 [p :ptr<void>] :nil)

free an atomic cell allocated by atomic-new.

patomic cell pointer from atomic-new

Since: Phase T19