perf fut: use Domain_.relax in spin loops

This commit is contained in:
Simon Cruanes 2023-06-08 00:07:54 -04:00
parent f3228f87c7
commit 259fee2722
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -39,7 +39,7 @@ let on_result (self : _ t) (f : _ waiter) : unit =
let must_retry = not (A.compare_and_set self.st st (Waiting (f :: l))) in let must_retry = not (A.compare_and_set self.st st (Waiting (f :: l))) in
must_retry must_retry
do do
() Domain_.relax ()
done done
exception Already_fulfilled exception Already_fulfilled
@ -58,7 +58,7 @@ let fulfill (self : _ t) (r : _ result) : unit =
) else ) else
true true
do do
() Domain_.relax ()
done done
let[@inline] fulfill_idempotent self r = let[@inline] fulfill_idempotent self r =
@ -137,13 +137,18 @@ let bind ?on ~f fut : _ t =
fut2 fut2
let rec update_ (st : 'a A.t) f : 'a = let update_ (st : 'a A.t) f : 'a =
let x = A.get st in let rec loop () =
let y = f x in let x = A.get st in
if A.compare_and_set st x y then let y = f x in
y if A.compare_and_set st x y then
else y
update_ st f else (
Domain_.relax ();
loop ()
)
in
loop ()
let both a b : _ t = let both a b : _ t =
match peek a, peek b with match peek a, peek b with