diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-10-08 00:09:56 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-10-08 00:09:56 +0000 |
| commit | b7b1c74b43dd5403d9d087845c8098b197ad0969 (patch) | |
| tree | e05d49cf190b090bb388232ff4f74e30ed8d567c /lib | |
| parent | 33bc86c566b4e2418c17e063c7417beca30476ef (diff) | |
| download | RNT-b7b1c74b43dd5403d9d087845c8098b197ad0969.tar.gz RNT-b7b1c74b43dd5403d9d087845c8098b197ad0969.zip | |
Make `Handle.release` concurrency-safe
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/protocols/Handle.ml | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/protocols/Handle.ml b/lib/protocols/Handle.ml index 2514a7f..add2e1c 100644 --- a/lib/protocols/Handle.ml +++ b/lib/protocols/Handle.ml @@ -17,14 +17,14 @@ class type obj = object method protocols : protocol list end -type t = {valid: bool ref; refers_to: obj} +type t = {valid: bool Atomic.t; refers_to: obj} type 'a interface = {handle: t; interface: 'a} let object_of {valid; refers_to} = - if !valid then refers_to else failwith "Attempt to dereference an invalid handle!" + if (Atomic.get valid) then refers_to else failwith "Attempt to dereference an invalid handle!" let interface_of handle interface = {handle; interface} -let make o = {valid= ref true; refers_to= (o :> obj)} +let make o = {valid= Atomic.make true; refers_to= (o :> obj)} let into handle f = List.find_map f (object_of handle)#protocols |> Option.map (interface_of handle) let invoke {handle; interface} f = @@ -44,7 +44,7 @@ let to_string h = let o = (object_of h) in "#<" ^ o#to_string ^ " " ^ (Concepts. let release ({valid; _} as handle) = let o = object_of handle in - valid := false; - o#release + if Atomic.compare_and_set valid true false then + o#release let require f h = Option.to_result ~none:(Error.unimplemented_protocol (to_string h)) (f h) |
