Skip to content

Commit bdb8224

Browse files
committed
Avoid write barriers by checking target location before clearing
1 parent bb366bf commit bdb8224

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/kcas/kcas.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,16 @@ module Mode = struct
219219
exception Interference
220220
end
221221

222+
let[@inline] isnt_int x = not (Obj.is_int (Obj.repr x))
223+
222224
let rec release_after which = function
223225
| T Leaf -> true
224226
| T (Node node_r) ->
225227
if is_node node_r.lt then release_after which node_r.lt |> ignore;
226228
let state = node_r.state in
227229
if is_cas which state then begin
228230
state.which <- W After;
229-
state.before <- Obj.magic ();
231+
if isnt_int state.before then state.before <- Obj.magic ();
230232
resume_awaiters node_r.awaiters
231233
end;
232234
release_after which node_r.gt
@@ -238,7 +240,7 @@ let rec release_before which = function
238240
let state = node_r.state in
239241
if is_cas which state then begin
240242
state.which <- W Before;
241-
state.after <- Obj.magic ();
243+
if isnt_int state.after then state.after <- Obj.magic ();
242244
resume_awaiters node_r.awaiters
243245
end;
244246
release_before which node_r.gt
@@ -917,7 +919,7 @@ module Xt = struct
917919
else begin
918920
state.which <- W After;
919921
let before = state.before in
920-
state.before <- Obj.magic ();
922+
if isnt_int before then state.before <- Obj.magic ();
921923
(* Fenceless is safe inside transactions as each log update has a fence. *)
922924
let state_old = fenceless_get (as_atomic loc) in
923925
if cas_with_state loc before state state_old then begin

0 commit comments

Comments
 (0)