Skip to content

Commit

Permalink
Use backoff when removing awaiters
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Dec 24, 2023
1 parent 897da96 commit b49c217
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/kcas/kcas.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ let[@tail_mod_cons] rec remove_first x' removed = function
[]
| x :: xs -> if x == x' then xs else x :: remove_first x' removed xs

let rec remove_awaiter loc before awaiter =
let rec remove_awaiter backoff loc before awaiter =
(* Fenceless is safe as we have fence after. *)
let state_old = fenceless_get (as_atomic loc) in
if before == eval state_old then
Expand All @@ -430,15 +430,15 @@ let rec remove_awaiter loc before awaiter =
{ before = Obj.magic (); after = before; which = W After; awaiters }
in
if not (Atomic.compare_and_set (as_atomic loc) state_old state_new) then
remove_awaiter loc before awaiter
remove_awaiter (Backoff.once backoff) loc before awaiter

let block timeout loc before =
let t = Domain_local_await.prepare_for_await () in
let alive = Timeout.await timeout t.release in
if add_awaiter loc before t.release then begin
try t.await ()
with cancellation_exn ->
remove_awaiter loc before t.release;
remove_awaiter Backoff.default loc before t.release;
Timeout.cancel_alive alive;
raise cancellation_exn
end;
Expand Down Expand Up @@ -862,7 +862,7 @@ module Xt = struct
| T (Node node_r) as current ->
if is_node node_r.lt then remove_awaiters awaiter which stop node_r.lt;
if current != stop then begin
remove_awaiter node_r.loc
remove_awaiter Backoff.default node_r.loc
(let state = node_r.state in
if is_cmp which state then eval state else state.before)
awaiter;
Expand Down

0 comments on commit b49c217

Please sign in to comment.