jon.recoil.org

Module Capsule_expert.KeySource

Keys represent the ownership of the capsule.

Sourcetype 'k t

'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.

Sourcetype 'k boxed

A boxed version of Key.t for places where you need a type with layout value.

Sourceval box : 'k Capsule_expert.Key.t @ portable -> 'k Capsule_expert.Key.boxed @ portable @@ portable
Sourceval unbox : 'k Capsule_expert.Key.boxed @ portable -> 'k Capsule_expert.Key.t @ portable @@ portable
Sourceval box_aliased : 'k Capsule_expert.Key.t -> 'k Capsule_expert.Key.boxed @@ portable
Sourceval unbox_aliased : 'k Capsule_expert.Key.boxed -> 'k Capsule_expert.Key.t @@ portable
Sourceval with_password : ('a : value_or_null) 'k. 'k Capsule_expert.Key.t @ portable -> f:('k Capsule_expert.Password.t @ local -> 'a @ portable) @ local local -> #('a * 'k Capsule_expert.Key.t) @ portable @@ portable

with_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.

Sourceval with_password_local : ('a : value_or_null) 'k. 'k Capsule_expert.Key.t @ portable -> f:('k Capsule_expert.Password.t @ local -> 'a @ local) @ local local -> 'a @ local @@ portable

with_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.

Sourceval with_password_shared : ('a : value_or_null) 'k. 'k Capsule_expert.Key.t -> f: ('k Capsule_expert.Password.Shared.t @ local -> 'a @ portable) @ local local -> 'a @ portable @@ portable

with_password_shared k ~f runs f, providing it a shared password for 'k, and returns the result of f.

Sourceval with_password_shared_local : ('a : value_or_null) 'k. 'k Capsule_expert.Key.t -> f:('k Capsule_expert.Password.Shared.t @ local -> 'a @ local) @ local local -> 'a @ local @@ portable

As with_password_shared, but returns a local value.

Sourceval access : ('a : value_or_null) 'k. 'k Capsule_expert.Key.t @ portable -> f: ('k Capsule_expert.Access.t -> 'a @ portable local portable contended) @ local local portable -> #('a * 'k Capsule_expert.Key.t) @ portable local portable contended @@ portable

access 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.

Sourceval access_local : ('a : value_or_null) 'k. 'k Capsule_expert.Key.t @ portable -> f: ('k Capsule_expert.Access.t -> 'a @ local portable local portable contended) @ local local portable -> #('a * 'k Capsule_expert.Key.t) @ local portable local portable contended @@ portable

As access, but local.

Sourceval access_shared : ('a : value_or_null) 'k. 'k Capsule_expert.Key.t -> f: ('k Capsule_expert.Access.t @ local -> 'a @ portable local portable contended) @ local local portable -> 'a @ portable local portable contended @@ portable

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.

Sourceval access_shared_local : ('a : value_or_null) 'k. 'k Capsule_expert.Key.t -> f: ('k Capsule_expert.Access.t @ local -> 'a @ local portable local portable contended) @ local local portable -> 'a @ local portable local portable contended @@ portable

As access_shared, but returns a local value.

Sourceval globalize_unique : 'k Capsule_expert.Key.t @ local portable -> 'k Capsule_expert.Key.t @ portable @@ portable

globalize_unique k promotes a local unique key to a global one.

Sourceval destroy : 'k Capsule_expert.Key.t @ local portable -> 'k Capsule_expert.Access.t @@ portable

destroy k returns 'k Access.t for 'k, merging it with the current capsule. The key is destroyed.

Sourceval unsafe_mk : unit -> 'k Capsule_expert.Key.t @ portable @@ portable

unsafe_mk () unsafely makes a unique key for an arbitrary capsule.