Skip to content

Commit

Permalink
Merge pull request #11233 from Octachron/atomic_gc_alarms
Browse files Browse the repository at this point in the history
stdlib audit: make gc alarms atomic
  • Loading branch information
gasche committed May 2, 2022
2 parents b02c7ca + 690ad7e commit 57e4d70
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stdlib/gc.ml
Expand Up @@ -102,23 +102,23 @@ external finalise_last : (unit -> unit) -> 'a -> unit =
external finalise_release : unit -> unit = "caml_final_release"


type alarm = bool ref
type alarm = bool Atomic.t
type alarm_rec = {active : alarm; f : unit -> unit}

let rec call_alarm arec =
if !(arec.active) then begin
if Atomic.get arec.active then begin
finalise call_alarm arec;
arec.f ();
end


let create_alarm f =
let arec = { active = ref true; f = f } in
let arec = { active = Atomic.make true; f = f } in
finalise call_alarm arec;
arec.active


let delete_alarm a = a := false
let delete_alarm a = Atomic.set a false

module Memprof =
struct
Expand Down

0 comments on commit 57e4d70

Please sign in to comment.