Capsule_expert.KeyKeys represent the ownership of the capsule.
'k t @ unique represents the exclusive ownership of the capsule 'k. The uniqueness of 'k t guarantees that only one thread can access the capsule at a time.
Obtaining a unique 'k t requires either calling Capsule.create or acquiring a synchronization primitive associated with 'k. Such primitives are provided by the Await library.
'k t @ aliased indicates that the key has been permanently shared, since it's avaiable aliased and therefore not available uniquely. Therefore, we can allow all threads read access to 'k.
val with_password :
'a 'k. 'k t @ unique ->
(f:('k Password.t @ local -> 'a @ unique) @ local once ->
#('a * 'k t) @ unique) @ once @@ portablewith_password k ~f runs f, providing it a password for 'k, and returns the result of f together with the key.
If f raises an exception, the key is destroyed, leaking the contents of the capsule.
val with_password_local :
'a 'k. 'k t @ unique ->
(f:('k Password.t @ local -> 'a @ local) @ local once ->
'a @ local) @ once @@ portablewith_password_local k ~f runs f, providing it a password for 'k, and returns the result of f. The key is destroyed, but the local password can be returned to provide access to the capsule.
with_password_shared k ~f runs f, providing it a shared password for 'k, and returns the result of f.
As with_password_shared, but returns a local value.
val access :
'a 'k. 'k t @ unique ->
(f:('k Access.t -> 'a @ unique once portable contended) @ local once portable ->
#('a * 'k t) @ unique once portable contended) @ once @@ portableaccess k ~f runs f, providing it access to the capsule 'k, and returns the result of f together with the key.
If f raises an exception, the key is destroyed, leaking the contents of the capsule, and the exception is reraised.
val access_local :
'a 'k. 'k t @ unique ->
(f:
('k Access.t -> 'a @ local unique once portable contended) @ local once portable ->
#('a * 'k t) @ local unique once portable contended) @ once @@ portableAs access, but local.
access_shared k ~f runs f, providing it a shared access to 'k, and returns the result of f. Exceptions raised from f are re-raised.
As access_shared, but returns a local value.
globalize_unique k promotes a local unique key to a global one.
destroy k returns 'k Access.t for 'k, merging it with the current capsule. The key is destroyed.
val unsafe_mk : unit -> 'k t @ unique @@ portableunsafe_mk () unsafely makes a unique key for an arbitrary capsule.