aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/kernel/BranchManager.ml1
-rw-r--r--lib/kernel/Initialization.ml2
-rw-r--r--lib/kernel/Namespace.ml42
3 files changed, 16 insertions, 29 deletions
diff --git a/lib/kernel/BranchManager.ml b/lib/kernel/BranchManager.ml
index cd3c5e2..596a1cb 100644
--- a/lib/kernel/BranchManager.ml
+++ b/lib/kernel/BranchManager.ml
@@ -33,6 +33,7 @@ module Make (S : Abstract.Storage.STORAGE) = struct
class manager storage label head = object (self)
inherit Lifecycle.null
+ inherit Identity.of_id
val storage : S.connection = storage
val label : string = label
diff --git a/lib/kernel/Initialization.ml b/lib/kernel/Initialization.ml
index 3eb8aed..ab91dbc 100644
--- a/lib/kernel/Initialization.ml
+++ b/lib/kernel/Initialization.ml
@@ -7,6 +7,6 @@ module Make (S : Abstract.Storage.STORAGE) = struct
let root = Namespace.make () in
let registry = Registry.from root |> Option.get in
let* branch = BM.make conn "rnt-head" in
- let* () = Registry.register registry "branch" branch in
+ let* _ = Registry.update registry "branch" None (Some branch) in
Ok root
end
diff --git a/lib/kernel/Namespace.ml b/lib/kernel/Namespace.ml
index 20f83f5..507afa4 100644
--- a/lib/kernel/Namespace.ml
+++ b/lib/kernel/Namespace.ml
@@ -1,39 +1,25 @@
-module Errors = struct
- include Concepts.Condition
-
- let key_already_exists key =
- condition "key-already-exists" "The specified key already exists in the namespace"
- ("key" |=| Concepts.Value.String key)
-
- let no_such_key key =
- condition "no-such-key" "The specified key does not exist in the namespace"
- ("key" |=| Concepts.Value.String key)
-end
-
class namespace = object (self)
inherit Lifecycle.null
+ inherit Identity.of_id
val entries : (string, Protocols.Handle.t) BatMap.t Atomic.t =
Atomic.make BatMap.empty
method protocols = Protocols.[Directory.make self; Registry.make self]
- method register key value =
- Utilities.Atomic.mswap entries
- (fun e ->
- match BatMap.find_opt key e with
- | None -> Ok (BatMap.add key value e)
- | Some _ -> Error (Errors.key_already_exists key))
- |> Result.map ignore
-
- method unregister key =
- Utilities.Atomic.mswap entries
- (fun e ->
- try
- Ok (BatMap.remove_exn key e)
- with Not_found ->
- Error (Errors.no_such_key key))
- |> Result.map ignore
+ method update key reference value =
+ match
+ Utilities.Atomic.mswap entries
+ (fun e ->
+ if BatMap.find_opt key e = reference then
+ match value with
+ | Some v -> Ok (BatMap.add key v e)
+ | None -> Ok (BatMap.remove key e)
+ else
+ Error ())
+ with
+ | Ok _ -> Ok true
+ | Error _ -> Ok false
method list =
Atomic.get entries