aboutsummaryrefslogtreecommitdiffstats
path: root/lib/protocols/Handle.ml
diff options
context:
space:
mode:
authorEstevan Castilho <tevo@riajuu.net>2026-10-10 01:09:17 +0000
committerEstevan Castilho <tevo@riajuu.net>2026-10-10 01:09:17 +0000
commit9be5137143177492e82dc25e6dbd3b82e3aa7e5d (patch)
treed2206c6c67a395cc1e6f3b1e47c2da812a83bf96 /lib/protocols/Handle.ml
parentbd152dc4311a117f125916e1f75cb5ce02752630 (diff)
downloadRNT-9be5137143177492e82dc25e6dbd3b82e3aa7e5d.tar.gz
RNT-9be5137143177492e82dc25e6dbd3b82e3aa7e5d.zip
Make namespaces take ownership of the handles it is given
Diffstat (limited to 'lib/protocols/Handle.ml')
-rw-r--r--lib/protocols/Handle.ml11
1 files changed, 9 insertions, 2 deletions
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