tur/atomic
stdlib/atomic.tur
defn
atomic-new
(atomic-new [init :int] :ptr<void>)
allocate a heap-based atomic int64 cell initialised to init.
Parameters
| init | initial 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.
Parameters
| p | atomic 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.
Parameters
| p | atomic cell pointer from atomic-new | |
| v | new 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.
Parameters
| p | atomic cell pointer from atomic-new | |
| delta | amount 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.
Parameters
| p | atomic cell pointer from atomic-new | |
| delta | amount 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.
Parameters
| p | atomic cell pointer from atomic-new | |
| new-val | value 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.
Parameters
| p | atomic cell pointer from atomic-new | |
| expected | value to compare against | |
| desired | value 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.
Parameters
| p | atomic cell pointer from atomic-new |
Since: Phase T19