From 9be5137143177492e82dc25e6dbd3b82e3aa7e5d Mon Sep 17 00:00:00 2001 From: Estevan Castilho Date: Sat, 10 Oct 2026 01:09:17 +0000 Subject: Make namespaces take ownership of the handles it is given --- lib/protocols/Handle.ml | 11 +++++++++-- lib/protocols/Handle.mli | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/protocols') diff --git a/lib/protocols/Handle.ml b/lib/protocols/Handle.ml index 6f7ca43..b8dd691 100644 --- a/lib/protocols/Handle.ml +++ b/lib/protocols/Handle.ml @@ -26,9 +26,11 @@ let object_of {valid; refers_to; _} = let to_string h = let o = (object_of h) in "#<" ^ o#to_string ^ " " ^ (Concepts.Hash.to_hum_string o#hash) ^ ">" -let release ({valid; _} as handle) = +let invalidate {valid; _} = Atomic.compare_and_set valid true false + +let release handle = let o = object_of handle in - if Atomic.compare_and_set valid true false then + if invalidate handle then o#release let on_gc ({valid; refers_to; allocated_at} as h) = @@ -94,6 +96,11 @@ let copy handle = let o = object_of handle in if o#reference then Some (make o) else None +let move handle = + let o = object_of handle in + invalidate handle |> ignore; + make o + let equal h1 h2 = Concepts.Hash.hash_equals (object_of h1)#hash (object_of h2)#hash let hash h = (object_of h)#hash let protocols h = (object_of h)#protocols diff --git a/lib/protocols/Handle.mli b/lib/protocols/Handle.mli index f1a9609..47cee38 100644 --- a/lib/protocols/Handle.mli +++ b/lib/protocols/Handle.mli @@ -16,6 +16,7 @@ val into : t -> (protocol -> 'a option) -> 'a interface option val from : 'a interface -> t val invoke : 'a interface -> ('a -> 'b) -> 'b val copy : t -> t option +val move : t -> t val equal : t -> t -> bool val release : t -> unit val hash : t -> Concepts.Hash.hash @@ -24,4 +25,5 @@ val to_string : t -> string val require : (t -> 'a interface option) -> t -> ('a interface, Concepts.Condition.condition) result val with_autorelease : (unit -> 'a) -> 'a val without_autorelease : (unit -> 'a) -> 'a +val autorelease : t -> unit val keep : t -> unit -- cgit v1.2.3