From 6d5de2a131897b89a8df19d1d6c13a11028ea8a0 Mon Sep 17 00:00:00 2001 From: Vesa Karvonen Date: Wed, 16 Oct 2024 14:44:43 +0300 Subject: [PATCH] More performance tweaks --- lib/picos/picos.ocaml5.ml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/picos/picos.ocaml5.ml b/lib/picos/picos.ocaml5.ml index 1dd78998..d0222c5c 100644 --- a/lib/picos/picos.ocaml5.ml +++ b/lib/picos/picos.ocaml5.ml @@ -10,21 +10,25 @@ module Trigger = struct and t = state Atomic.t - let finish t ~allow_awaiting = + let finish t ~run_action = match Atomic.get t with | Signaled -> () | Awaiting r as before -> - if allow_awaiting then begin - if Atomic.compare_and_set t before Signaled then r.action t r.x r.y - end - else error_awaiting before + if + Bool.to_int (Atomic.compare_and_set t before Signaled) + land Bool.to_int run_action + != 0 + then r.action t r.x r.y | Initial -> if not (Atomic.compare_and_set t Initial Signaled) then begin match Atomic.get t with | Signaled | Initial -> () | Awaiting r as before -> - if allow_awaiting && Atomic.compare_and_set t before Signaled then - r.action t r.x r.y + if + Bool.to_int (Atomic.compare_and_set t before Signaled) + land Bool.to_int run_action + != 0 + then r.action t r.x r.y end let on_signal t x y action = @@ -52,8 +56,8 @@ module Trigger = struct let[@inline] from_action x y action = Atomic.make (Awaiting { action; x; y }) let[@inline] is_signaled t = Atomic.get t == Signaled - let[@inline] signal t = finish t ~allow_awaiting:true - let[@inline] dispose t = finish t ~allow_awaiting:false + let[@inline] signal t = finish t ~run_action:true + let[@inline] dispose t = finish t ~run_action:false (* END TRIGGER BOOTSTRAP *) @@ -293,7 +297,7 @@ module Computation = struct end let detach t trigger = - Trigger.signal trigger; + Trigger.dispose trigger; unsafe_unsuspend t Backoff.default |> ignore (** This cannot be [@@unboxed] because [Atomic.t] is opaque *)