(sagittarius atomic) - Atomic operation

Library (sagittarius atomic) 0.9.13

This library provides atomic operation. The underlying implementation of this library can be either stdatomic from C11 or <atomic> from C++11. If the platform supports the first one, then that'd be chosen, otherwise the latter one.

NOTE: if the platform doesn't support none of them, then compilation error.

Function atomic? obj

Returns #t if the given obj is an atomic object, otherwise #f.

Function make-atomic obj

Creates a fresh atomic object whoes initial value is obj.

Function atomic-flag? obj

Returns #t if the given obj is an atomic flag object, otherwise #f.

Function make-atomic-flag

Creates a fresh atomic flag. The flag is unset.

Function atomic-fixnum? obj

Returns #t if the given obj is an atomic fixnum object, otherwise #f.

Function make-atomic-fixnum ( n fixnum? )

Creates a fresh atomic fixnum object whoes initial value is n.

Function atomic-pair? obj

Returns #t if the given obj is an atomic pair object, otherwise #f.

Function make-atomic-pair head tail

Creates a fresh atomic pair object whoes initial values are first and tail.

This is double word atomic object.

Function memory-order? obj

Returns #t if the given obj is a fixnum and value of memory order.

Constant *memory-order:relaxed*
Constant *memory-order:consume*
Constant *memory-order:acquire*
Constant *memory-order:release*
Constant *memory-order:acq-rel*
Constant *memory-order:seq-cst*

The memory order values. The meanings are the same as C11.

If the libatomic_ops is used as underlying implementation, then it translate them with the best effort.

Function atomic-load ( a atomic? ) :optional ( order memory-order? )

Loads the current value of the given atomic of a.

Function atomic-store! ( a atomic? ) v :optional ( order memory-order? )

Stores the given value v into the atomic a.

Function atomic-fixnum-load ( a atomic-fixnum? ) :optional ( order memory-order? )

Loads the current value of the given atomic of a.

Function atomic-fixnum-store! ( a atomic-fixnum? ) ( n fixnum? ) :optional ( order memory-order? )

Stores the given value n into the atomic a. The return value is unspecified.

Function atomic-fixnum-add! ( a atomic-fixnum? ) ( n fixnum? ) :optional ( order memory-order? )
Function atomic-fixnum-sub! ( a atomic-fixnum? ) ( n fixnum? ) :optional ( order memory-order? )
Function atomic-fixnum-ior! ( a atomic-fixnum? ) ( n fixnum? ) :optional ( order memory-order? )
Function atomic-fixnum-xor! ( a atomic-fixnum? ) ( n fixnum? ) :optional ( order memory-order? )
Function atomic-fixnum-and! ( a atomic-fixnum? ) ( n fixnum? ) :optional ( order memory-order? )

Operates the addition, subtraction, bitwise or, bitwise xor and bitwise and against the value of atomic a with given n and updates the value of a and returns the previous value of a.

Function atomic-exchange! ( a atomic? ) v :optional ( order memory-order? )
Function atomic-fixnum-exchange! ( a atomic-fixnum? ) ( n fixnum? ) :optional ( order memory-order? )

Exchange the value of a with given v or n and returns the old value of a.

Function atomic-compare-and-swap! ( a atomic? ) e v :optional ( order memory-order? )

CAS operation. Returns #t if the operation succeed, otherwise #f.

Function atomic-fetch-compare-and-swap! ( a atomic? ) e v :optional ( order memory-order? )

CAS operation. Returns previously set value if the operation failed, otherwise the e.

Function atomic-fixnum-inc! ( a atomic-fixnum? ) :optional ( order memory-order? )
Function atomic-fixnum-dec! ( a atomic-fixnum? ) :optional ( order memory-order? )

Increment or decrement the value of given a and updates the value.

Function atomic-thread-fence ( order memory-order? )

Establishes memory synchronization ordering of non-atomic and relaxed atomic accesses.