Module Portable_kernel.Atomic_array

module Compare_failed_or_set_here = Atomic.Compare_failed_or_set_here
type !('a : value_or_null) t

Represents an array of atomic locations.

This is essentially a 'a Core.Atomic.t array, except it avoids the extra indirection of an atomic ref at each index.

include sig ... end
val sexp_of_t : 'a. ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
val compare : 'a. ('a -> 'a -> Base.int) -> 'a t -> 'a t -> Base.int
val compare__local : 'a. ('a @ local -> ('a @ local -> Base.int) @ local) -> 'a t @ local -> ('a t @ local -> Base.int) @ local
val equal : 'a. ('a -> 'a -> Base.bool) -> 'a t -> 'a t -> Base.bool
val equal__local : 'a. ('a @ local -> ('a @ local -> Base.bool) @ local) -> 'a t @ local -> ('a t @ local -> Base.bool) @ local
include sig ... end
val t_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a t
include sig ... end
val create : 'a. len:Base.int -> 'a @ portable contended -> 'a t @@ portable

create ~len value creates a new array of n atomic locations having given value.

val init : 'a. Base.int -> f:(Base.int -> 'a @ portable contended) @ local -> 'a t @@ portable

init n ~f returns a fresh atomic array of length n, with element number i initialized to the result of f i.

val of_list : 'a. 'a Base.list @ portable contended -> 'a t @@ portable

of_list l returns a fresh atomic array containing the elements of the list l.

val to_list : 'a. 'a t @ local -> 'a Base.list @ portable contended @@ portable

to_list atomic_array returns a list containing the elements of the atomic array atomic_array. The loads of the elements of the array to populate the list are done atomically.

val length : 'a. 'a t @ local -> Base.int @@ portable

length atomic_array returns the length of the atomic_array.

val get : 'a. 'a t @ local -> (Base.int -> 'a @ portable contended) @ local @@ portable

get atomic_array index reads and returns the value at the specified index of the atomic_array. Raises Invalid_argument if index is out of bounds.

val set : 'a. 'a t @ local -> (Base.int -> ('a @ portable contended -> Base.unit) @ local) @ local @@ portable

set atomic_array index value writes the given value to the specified index of the atomic_array. Raises Invalid_argument if index is out of bounds.

val exchange : 'a. 'a t @ local -> (Base.int -> ('a @ portable contended -> 'a @ portable contended) @ local) @ local @@ portable

exchange atomic_array index value sets the value at index to value, and returns the previous value. Raises Invalid_argument if index is out of bounds.

val compare_and_set : 'a. 'a t @ local -> (Base.int -> (if_phys_equal_to:'a @ contended -> (replace_with:'a @ portable contended -> Compare_failed_or_set_here.t) @ local) @ local) @ local @@ portable

compare_and_set atomic_array index ~if_phys_equal_to ~replace_with atomically updates the specified index of the atomic_array to replace_with only if its current value is physically equal to if_phys_equal_to -- the comparison and the set occur atomically. Returns Set_here if the update was successful, or Compare_failed otherwise. Raises Invalid_argument if index is out of bounds.

val compare_exchange : 'a. 'a t @ local -> (Base.int -> (if_phys_equal_to:'a @ contended -> (replace_with:'a @ portable contended -> 'a @ portable contended) @ local) @ local) @ local @@ portable

compare_exchange atomic_array index ~if_phys_equal_to ~replace_with sets the new value at index to replace_with only if its current value is physically equal to if_phys_equal_to -- the comparison and the set occur atomically. Returns the previous value at index, or the current (unchanged) value if the comparison failed. Raises Invalid_argument if index is out of bounds.

val fetch_and_add : Base.int t @ local -> (Base.int -> (Base.int -> Base.int) @ local) @ local @@ portable

fetch_and_add atomic_array index n atomically increments the value at index by n, and returns the previous value (before the increment). Raises Invalid_argument if index is out of bounds.

val add : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable

add atomic_array index i atomically adds i to the value at index. Raises Invalid_argument if index is out of bounds.

val sub : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable

sub atomic_array index i atomically subtracts i from the value at index. Raises Invalid_argument if index is out of bounds.

val logand : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable

logand atomic_array index i atomically bitwise-ands i onto the value at index. Raises Invalid_argument if index is out of bounds.

val logor : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable

logor atomic_array index i atomically bitwise-ors i onto the value at index. Raises Invalid_argument if index is out of bounds.

val logxor : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable

logxor atomic_array index i atomically bitwise-xors i onto the value at index. Raises Invalid_argument if index is out of bounds.

val incr : Base.int t @ local -> (Base.int -> Base.unit) @ local @@ portable

incr atomic_array index atomically increments the value at index by 1. Raises Invalid_argument if index is out of bounds.

val decr : Base.int t @ local -> (Base.int -> Base.unit) @ local @@ portable

decr atomic_array index atomically decrements the value at index by 1. Raises Invalid_argument if index is out of bounds.

Unsafe versions that do not perform bounds checking

val unsafe_get : 'a. 'a t @ local -> (Base.int -> 'a @ portable contended) @ local @@ portable
val unsafe_set : 'a. 'a t @ local -> (Base.int -> ('a @ portable contended -> Base.unit) @ local) @ local @@ portable
val unsafe_exchange : 'a. 'a t @ local -> (Base.int -> ('a @ portable contended -> 'a @ portable contended) @ local) @ local @@ portable
val unsafe_compare_and_set : 'a. 'a t @ local -> (Base.int -> (if_phys_equal_to:'a @ contended -> (replace_with:'a @ portable contended -> Compare_failed_or_set_here.t) @ local) @ local) @ local @@ portable
val unsafe_compare_exchange : 'a. 'a t @ local -> (Base.int -> (if_phys_equal_to:'a @ contended -> (replace_with:'a @ portable contended -> 'a @ portable contended) @ local) @ local) @ local @@ portable
val unsafe_fetch_and_add : Base.int t @ local -> (Base.int -> (Base.int -> Base.int) @ local) @ local @@ portable
val unsafe_add : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable
val unsafe_sub : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable
val unsafe_land : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable
val unsafe_lor : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable
val unsafe_lxor : Base.int t @ local -> (Base.int -> (Base.int -> Base.unit) @ local) @ local @@ portable