From 9e219b761aae357b8cb1c2e3e8e90ad4a57f6ca8 Mon Sep 17 00:00:00 2001 From: Carine Morel Date: Sun, 17 Nov 2024 19:45:36 +0100 Subject: [PATCH] Rename pop to pop_exn and steal to steal_exn --- bench/bench_ws_deque.ml | 16 +++++++++------- src/ws_deque.ml | 4 ++-- src/ws_deque.mli | 8 ++++---- test/ws_deque/qcheck_ws_deque.ml | 14 +++++++------- test/ws_deque/stm_ws_deque.ml | 4 ++-- test/ws_deque/test_ws_deque.ml | 14 +++++++------- test/ws_deque/ws_deque_dscheck.ml | 8 ++++---- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/bench/bench_ws_deque.ml b/bench/bench_ws_deque.ml index f822ef9c..fe39af69 100644 --- a/bench/bench_ws_deque.ml +++ b/bench/bench_ws_deque.ml @@ -14,13 +14,13 @@ let run_as_scheduler ~budgetf ?(n_domains = 1) () = in let rec try_own own = - match Ws_deque.pop (Array.unsafe_get deques own) with + match Ws_deque.pop_exn (Array.unsafe_get deques own) with | work -> work | exception Exit -> try_steal own (next own) and try_steal own other = if other = own then raise_notrace Exit else - match Ws_deque.steal (Array.unsafe_get deques other) with + match Ws_deque.steal_exn (Array.unsafe_get deques other) with | work -> work | exception Exit -> try_steal own (next other) in @@ -90,14 +90,15 @@ let run_as_one_domain ~budgetf ?(n_msgs = 150 * Util.iter_factor) order = let op_lifo push = if push then Ws_deque.push t 101 - else match Ws_deque.pop t with _ -> () | exception Exit -> () + else match Ws_deque.pop_exn t with _ -> () | exception Exit -> () and op_fifo push = if push then Ws_deque.push t 101 - else match Ws_deque.steal t with _ -> () | exception Exit -> () + else match Ws_deque.steal_exn t with _ -> () | exception Exit -> () in let init _ = - assert (match Ws_deque.steal t with _ -> false | exception Exit -> true); + assert ( + match Ws_deque.steal_exn t with _ -> false | exception Exit -> true); Util.generate_push_and_pop_sequence n_msgs in let work _ bits = @@ -121,7 +122,8 @@ let run_as_spmc ~budgetf ~n_thiefs () = let n_msgs_to_steal = Atomic.make 0 |> Multicore_magic.copy_as_padded in let init _ = - assert (match Ws_deque.steal t with _ -> false | exception Exit -> true); + assert ( + match Ws_deque.steal_exn t with _ -> false | exception Exit -> true); Atomic.set n_msgs_to_steal n_msgs in let work i () = @@ -131,7 +133,7 @@ let run_as_spmc ~budgetf ~n_thiefs () = if 0 < n then let rec loop n = if 0 < n then - match Ws_deque.steal t with + match Ws_deque.steal_exn t with | exception Exit -> Domain.cpu_relax (); loop n diff --git a/src/ws_deque.ml b/src/ws_deque.ml index 6037e15f..ff14a1bb 100644 --- a/src/ws_deque.ml +++ b/src/ws_deque.ml @@ -124,7 +124,7 @@ let pop_as : type a r. a t -> (a, r) poly -> r = match poly with Option -> None | Value -> raise_notrace Exit end -let pop q = pop_as q Value +let pop_exn q = pop_as q Value let pop_opt q = pop_as q Option let rec steal_as : type a r. a t -> Backoff.t -> (a, r) poly -> r = @@ -146,5 +146,5 @@ let rec steal_as : type a r. a t -> Backoff.t -> (a, r) poly -> r = else steal_as q (Backoff.once backoff) poly else match poly with Option -> None | Value -> raise_notrace Exit -let steal q = steal_as q Backoff.default Value +let steal_exn q = steal_as q Backoff.default Value let steal_opt q = steal_as q Backoff.default Option diff --git a/src/ws_deque.mli b/src/ws_deque.mli index 08654e09..e1abd86d 100644 --- a/src/ws_deque.mli +++ b/src/ws_deque.mli @@ -25,8 +25,8 @@ val push : 'a t -> 'a -> unit (** [push t v] adds [v] to the front of the queue [q]. It should only be invoked by the domain which owns the queue [q]. *) -val pop : 'a t -> 'a -(** [pop q] removes and returns the first element in queue +val pop_exn : 'a t -> 'a +(** [pop_exn q] removes and returns the first element in queue [q].It should only be invoked by the domain which owns the queue [q]. @@ -39,8 +39,8 @@ val pop_opt : 'a t -> 'a option (** {1 Stealers function} *) -val steal : 'a t -> 'a -(** [steal q] removes and returns the last element from queue +val steal_exn : 'a t -> 'a +(** [steal_exn q] removes and returns the last element from queue [q]. It should only be invoked by domain which doesn't own the queue [q]. diff --git a/test/ws_deque/qcheck_ws_deque.ml b/test/ws_deque/qcheck_ws_deque.ml index 1a2a52d5..b90a34a9 100644 --- a/test/ws_deque/qcheck_ws_deque.ml +++ b/test/ws_deque/qcheck_ws_deque.ml @@ -33,7 +33,7 @@ let tests_one_producer = let deque = deque_of_list (l @ l') in let pop_list = - extract_n_of_deque deque Ws_deque.pop (List.length l') + extract_n_of_deque deque Ws_deque.pop_exn (List.length l') in pop_list = List.rev l')); (* TEST 2 - single producer no stealer : @@ -49,7 +49,7 @@ let tests_one_producer = let deque = deque_of_list l in for _i = 0 to m - 1 do - try ignore (Ws_deque.pop deque) with Exit -> incr count + try ignore (Ws_deque.pop_exn deque) with Exit -> incr count done; !count = m - n)); @@ -77,7 +77,7 @@ let tests_one_producer_one_stealer = let stealer = Domain.spawn (fun () -> let steal' deque = - match Ws_deque.steal deque with + match Ws_deque.steal_exn deque with | value -> Some value | exception Exit -> Domain.cpu_relax (); @@ -124,7 +124,7 @@ let tests_one_producer_one_stealer = Domain.spawn (fun () -> Barrier.await barrier; let steal' deque = - match Ws_deque.steal deque with + match Ws_deque.steal_exn deque with | value -> Some value | exception Exit -> Domain.cpu_relax (); @@ -175,7 +175,7 @@ let tests_one_producer_one_stealer = let barrier = Barrier.create 2 in Random.self_init (); let pop' deque = - match Ws_deque.pop deque with + match Ws_deque.pop_exn deque with | value -> Some value | exception Exit -> Domain.cpu_relax (); @@ -189,7 +189,7 @@ let tests_one_producer_one_stealer = Domain.spawn (fun () -> Barrier.await barrier; let steal' deque = - match Ws_deque.steal deque with + match Ws_deque.steal_exn deque with | value -> Some value | exception Exit -> Domain.cpu_relax (); @@ -242,7 +242,7 @@ let tests_one_producer_two_stealers = for i = 0 to nsteal - 1 do res.(i) <- - (match Ws_deque.steal deque with + (match Ws_deque.steal_exn deque with | value -> Some value | exception Exit -> Domain.cpu_relax (); diff --git a/test/ws_deque/stm_ws_deque.ml b/test/ws_deque/stm_ws_deque.ml index f11a23e6..5d023833 100644 --- a/test/ws_deque/stm_ws_deque.ml +++ b/test/ws_deque/stm_ws_deque.ml @@ -47,8 +47,8 @@ module Spec = struct let run c d = match c with | Push i -> Res (unit, Ws_deque.push d i) - | Pop -> Res (result int exn, protect Ws_deque.pop d) - | Steal -> Res (result int exn, protect Ws_deque.steal d) + | Pop -> Res (result int exn, protect Ws_deque.pop_exn d) + | Steal -> Res (result int exn, protect Ws_deque.steal_exn d) let postcond c (s : state) res = match (c, res) with diff --git a/test/ws_deque/test_ws_deque.ml b/test/ws_deque/test_ws_deque.ml index bc6a1bc5..fbe5f018 100644 --- a/test/ws_deque/test_ws_deque.ml +++ b/test/ws_deque/test_ws_deque.ml @@ -3,7 +3,7 @@ open Saturn.Work_stealing_deque let test_empty () = let q = create () in - match pop q with + match pop_exn q with | exception Exit -> print_string "test_exit: ok\n" | _ -> assert false @@ -12,9 +12,9 @@ let test_push_and_pop () = push q 1; push q 10; push q 100; - assert (pop q = 100); - assert (pop q = 10); - assert (pop q = 1); + assert (pop_exn q = 100); + assert (pop_exn q = 10); + assert (pop_exn q = 1); print_string "test_push_and_pop: ok\n" let test_push_and_steal () = @@ -25,7 +25,7 @@ let test_push_and_steal () = let domains = Array.init 3 (fun _ -> Domain.spawn (fun _ -> - let v = steal q in + let v = steal_exn q in assert (v = 1 || v = 10 || v = 100))) in Array.iter Domain.join domains; @@ -64,7 +64,7 @@ let test_concurrent_workload () = pushed := x :: !pushed; decr n and pop () = - match pop q with + match pop_exn q with | exception Exit -> Domain.cpu_relax (); false @@ -89,7 +89,7 @@ let test_concurrent_workload () = Array.init thieves (fun i -> Domain.spawn (fun () -> let steal () = - match steal q with + match steal_exn q with | exception Exit -> Domain.cpu_relax () | x -> stolen.(i) <- x :: stolen.(i) in diff --git a/test/ws_deque/ws_deque_dscheck.ml b/test/ws_deque/ws_deque_dscheck.ml index c8a3afce..1cfe9775 100644 --- a/test/ws_deque/ws_deque_dscheck.ml +++ b/test/ws_deque/ws_deque_dscheck.ml @@ -2,7 +2,7 @@ let drain_remaining queue = let remaining = ref 0 in (try while true do - Ws_deque.pop queue |> ignore; + Ws_deque.pop_exn queue |> ignore; remaining := !remaining + 1 done with _ -> ()); @@ -21,7 +21,7 @@ let owner_stealer () = Ws_deque.push queue 0 done; for _ = 1 to total_items / 2 do - match Ws_deque.pop queue with + match Ws_deque.pop_exn queue with | exception _ -> () | _ -> popped := !popped + 1 done); @@ -29,7 +29,7 @@ let owner_stealer () = (* stealer *) Atomic.spawn (fun () -> for _ = 1 to total_items / 2 do - match Ws_deque.steal queue with + match Ws_deque.steal_exn queue with | exception _ -> () | _ -> popped := !popped + 1 done); @@ -50,7 +50,7 @@ let popper_stealer () = (* stealers *) let popped = ref 0 in let stealer () = - match Ws_deque.steal queue with + match Ws_deque.steal_exn queue with | exception _ -> () | _ -> popped := !popped + 1 in