Skip to content

Commit

Permalink
Apply reviews.
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrm committed Nov 28, 2024
1 parent 040c62f commit 741ff23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/spsc_queue/spsc_queue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/spsc_queue/spsc_queue_intf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 741ff23

Please sign in to comment.