tur/atomic
atomic load/store/add/sub/swap/CAS on 64-bit integers.
Since: Phase T19
AtomicCell
(AtomicCell)
atomic-new
(atomic-new [init : int] :)
allocate a heap-based atomic int64 cell initialised to init.
| init | initial 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
atomic-load
(atomic-load [p : AtomicCell] :)
atomically read the current value of the cell.
| p | atomic cell pointer from atomic-new |
The current int64 value (sequentially-consistent load).
(atomic-load a) ; => 0
Since: Phase T19
atomic-store!
(atomic-store! [p : AtomicCell v : int] :)
atomically write v into the cell.
| p | atomic cell pointer from atomic-new | |
| v | new value to store |
Since: Phase T19
atomic-add!
(atomic-add! [p : AtomicCell delta : int] :)
atomically add delta and return the old value.
| p | atomic cell pointer from atomic-new | |
| delta | amount 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
atomic-sub!
(atomic-sub! [p : AtomicCell delta : int] :)
atomically subtract delta and return the old value.
| p | atomic cell pointer from atomic-new | |
| delta | amount to subtract |
The value of the cell before the subtraction.
Since: Phase T19
atomic-swap!
(atomic-swap! [p : AtomicCell new-val : int] :)
atomically replace the cell value with new-val and return the old value.
| p | atomic cell pointer from atomic-new | |
| new-val | value to store |
The value of the cell before the swap.
(atomic-swap! a 99) ; => old value; cell now holds 99
Since: Phase T19
atomic-cas!
(atomic-cas! [p : AtomicCell expected : int desired : int] :)
compare-and-swap: if cell == expected, set to desired and return true.
| p | atomic cell pointer from atomic-new | |
| expected | value to compare against | |
| desired | value 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
atomic-free
(atomic-free [p : AtomicCell] :)
free an atomic cell allocated by atomic-new.
| p | atomic cell pointer from atomic-new |
Since: Phase T19