tur/atomic

stdlib/atomic.tur
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

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

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)

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

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

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

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