From 741ff2390985c4ccca93467abe663fe7f90ec21b Mon Sep 17 00:00:00 2001 From: Carine Morel Date: Thu, 28 Nov 2024 17:35:46 +0100 Subject: [PATCH] Apply reviews. --- src/spsc_queue/spsc_queue.ml | 8 ++++---- src/spsc_queue/spsc_queue_intf.mli | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/spsc_queue/spsc_queue.ml b/src/spsc_queue/spsc_queue.ml index 8eee5a04..f62326c0 100644 --- a/src/spsc_queue/spsc_queue.ml +++ b/src/spsc_queue/spsc_queue.ml @@ -62,7 +62,7 @@ let of_list_exn ~size_exponent values = let nvalues = List.length values in if nvalues > size then raise Full; let array = Array.make size None in - List.iteri (fun i elt -> Array.unsafe_set array i (Some elt)) values; + List.iteri (fun i elt -> Array.set array i (Some elt)) values; let tail = Atomic.make_contended nvalues in let s = Obj.size (Obj.repr tail) in let tail_cache = Padded_int_ref.make s nvalues in @@ -86,7 +86,7 @@ let push_as (type r) t element (mono : r mono) : r = head == head_cache then match mono with Unit -> raise_notrace Full | Bool -> false else begin - Array.unsafe_set t.array (tail land (size - 1)) (Some element); + Array.set t.array (tail land (size - 1)) (Some element); Atomic.incr t.tail; match mono with Unit -> () | Bool -> true end @@ -115,11 +115,11 @@ let pop_or_peek_as (type a r) (t : a t) op (poly : (a, r) poly) : r = then match poly with Value | Unit -> raise_notrace Empty | Option -> None else let index = head land (Array.length t.array - 1) in - let v = Array.unsafe_get t.array index in + let v = Array.get t.array index in begin match op with | Pop -> - Array.unsafe_set t.array index None; + Array.set t.array index None; Atomic.incr t.head | Peek -> () end; diff --git a/src/spsc_queue/spsc_queue_intf.mli b/src/spsc_queue/spsc_queue_intf.mli index c6d3aaa4..1a4853dd 100644 --- a/src/spsc_queue/spsc_queue_intf.mli +++ b/src/spsc_queue/spsc_queue_intf.mli @@ -14,8 +14,10 @@ module type SPSC_queue = sig that works in FIFO order. *) val create : size_exponent:int -> 'a t - (** [create ~size_exponent:int] creates a new single-producer single-consumer - queue of maximum size [2^size_exponent] and initially empty. *) + (** [create ~size_exponent] creates a new single-producer single-consumer + queue with a maximum size of [2^size_exponent] and initially empty. + + 🐌 This is a linear-time operation in [2^size_exponent]. *) val of_list_exn : size_exponent:int -> 'a list -> 'a t (** [of_list_exn ~size_exponent list] creates a new queue from a list.