@@ -169,6 +169,66 @@ module Transparent_atomic : sig
169169 val decr : int t -> unit
170170end
171171
172+ (* * {1 Missing functionality} *)
173+
174+ module Atomic_array : sig
175+ (* * Array of (potentially unboxed) atomic locations.
176+
177+ Where available, this uses an undocumented operation exported by the OCaml
178+ 5 runtime,
179+ {{:https://github.com/ocaml/ocaml/blob/7a5d882d22cdd32b6319e9be680bd1a3d67377a9/runtime/memory.c#L313-L338}
180+ [caml_atomic_cas_field]}, which makes it possible to perform sequentially
181+ consistent atomic updates of record fields and array elements.
182+
183+ Hopefully a future version of OCaml provides more comprehensive and even
184+ more efficient support for both sequentially consistent and relaxed atomic
185+ operations on records and arrays. *)
186+
187+ type !'a t
188+ (* * Represents an array of atomic locations. *)
189+
190+ val make : int -> 'a -> 'a t
191+ (* * [make n value] creates a new array of [n] atomic locations having given
192+ [value]. *)
193+
194+ val of_array : 'a array -> 'a t
195+ (* * [of_array non_atomic_array] create a new array of atomic locations as a
196+ copy of the given [non_atomic_array]. *)
197+
198+ val init : int -> (int -> 'a ) -> 'a t
199+ (* * [init n fn] is equivalent to {{!of_array} [of_array (Array.init n fn)]}. *)
200+
201+ val length : 'a t -> int
202+ (* * [length atomic_array] returns the length of the [atomic_array]. *)
203+
204+ val unsafe_fenceless_get : 'a t -> int -> 'a
205+ (* * [unsafe_fenceless_get atomic_array index] reads and returns the value at
206+ the specified [index] of the [atomic_array].
207+
208+ ⚠️ The read is {i relaxed} and may be reordered with respect to other reads
209+ and writes in program order.
210+
211+ ⚠️ No bounds checking is performed. *)
212+
213+ val unsafe_fenceless_set : 'a t -> int -> 'a -> unit
214+ (* * [unsafe_fenceless_set atomic_array index value] writes the given [value]
215+ to the specified [index] of the [atomic_array].
216+
217+ ⚠️ The write is {i relaxed} and may be reordered with respect to other
218+ reads and (non-initializing) writes in program order.
219+
220+ ⚠️ No bounds checking is performed. *)
221+
222+ val unsafe_compare_and_set : 'a t -> int -> 'a -> 'a -> bool
223+ (* * [unsafe_compare_and_set atomic_array index before after] atomically
224+ updates the specified [index] of the [atomic_array] to the [after] value
225+ in case it had the [before] value and returns a boolean indicating whether
226+ that was the case. This operation is {i sequentially consistent} and may
227+ not be reordered with respect to other reads and writes in program order.
228+
229+ ⚠️ No bounds checking is performed. *)
230+ end
231+
172232(* * {1 Avoiding contention} *)
173233
174234val instantaneous_domain_index : unit -> int
0 commit comments