Module Capsule_expert.Data

Pointers to data within a capsule.

type ('a, 'k) t

('a, 'k) t is the type of 'as within the capsule 'k. It can be passed between threads. Operations on ('a, 'k) t require a 'k Password.t associated with the capsule 'k.

val wrap : access:'k Access.t -> 'a -> ('a, 'k) t @@ portable

wrap ~access v returns a pointer to the value v, which lives in the capsule 'k. 'k is always the current capsule.

val unwrap : access:'k Access.t -> ('a, 'k) t -> 'a @@ portable

unwrap ~access t returns the value of t, which lives in the capsule 'k. 'k is always the current capsule.

val wrap_unique : access:'k Access.t -> 'a @ unique -> ('a, 'k) t @ unique @@ portable

Like wrap, but for unique values.

val unwrap_unique : access:'k Access.t -> ('a, 'k) t @ unique -> 'a @ unique @@ portable

Like unwrap, but for unique values.

val wrap_once : access:'k Access.t -> 'a @ once -> ('a, 'k) t @ once @@ portable

Like wrap, but for once values.

val unwrap_once : access:'k Access.t -> ('a, 'k) t @ once -> 'a @ once @@ portable

Like unwrap, but for once values.

val wrap_once_unique : access:'k Access.t -> 'a @ unique once -> ('a, 'k) t @ unique once @@ portable

Like wrap, but for once unique values.

val unwrap_once_unique : access:'k Access.t -> ('a, 'k) t @ unique once -> 'a @ unique once @@ portable

Like unwrap, but for once unique values.

val unwrap_shared : 'a 'k. access:'k Access.t @ shared -> ('a, 'k) t -> 'a @ shared @@ portable

unwrap_shared ~access t returns the shared value of t, which lives in the capsule 'k. 'k is always the current capsule. Since 'a may have been shared with other threads, 'a must cross portability.

val create : (unit -> 'a) @ local once portable -> ('a, 'k) t @@ portable

create f runs f within the capsule 'k and returns a pointer to the result of f.

val create_once : (unit -> 'a @ once) @ local once portable -> ('a, 'k) t @ once @@ portable

Like create, but for once values.

val create_unique : (unit -> 'a @ unique) @ local once portable -> ('a, 'k) t @ unique @@ portable

create_unique f runs f within the capsule 'k and returns a pointer to the result of f.

val map : password:'k Password.t @ local -> (f:('a -> 'b) @ local once portable -> (('a, 'k) t -> ('b, 'k) t) @ local once) @ local @@ portable

map ~password ~f t applies f to the value of p within the capsule 'k and returns a pointer to the result.

val both : ('a, 'k) t -> ('b, 'k) t -> ('a * 'b, 'k) t @@ portable

both t1 t2 is a pointer to a pair of the values of t1 and t2.

val fst : ('a * 'b, 'k) t -> ('a, 'k) t @@ portable

fst t gives a pointer to the first value inside t

val snd : ('a * 'b, 'k) t -> ('b, 'k) t @@ portable

snd t gives a pointer to the second value inside t

val extract : password:'k Password.t @ local -> (f:('a -> 'b @ unique once portable contended) @ local once portable -> (('a, 'k) t -> 'b @ unique once portable contended) @ local once) @ local @@ portable

extract ~password ~f t applies f to the value of t within the capsule 'k and returns the result. The result is within 'k so must be portable and is marked contended.

val inject : 'a 'k. 'a @ portable -> ('a, 'k) t @@ portable

inject v creates a pointer to a value v injected into the capsule 'k. It's a specialization of create to values that are always uncontended.

val project : 'a 'k. ('a, 'k) t -> 'a @ contended @@ portable

project t returns the value of t. The result is within 'k, so is marked contended. The value is required to always be portable, so unlike extract, project does not require permission to access 'k. This is safe because all accesses to the value happen only after it's marked contended.

val project_shared : 'a 'k. key:'k Key.t -> ('a, 'k) t -> 'a @ shared @@ portable

project_shared ~key t is like project t, but since t is a capsule associated with a key @ aliased global, the contents can be returned at shared.

val project_shared_unique : 'a 'k. key:'k Key.t -> ('a, 'k) t @ unique -> 'a @ unique shared @@ portable
val bind : password:'k Password.t @ local -> (f:('a -> ('b, 'j) t) @ local once portable -> (('a, 'k) t -> ('b, 'j) t) @ local once) @ local @@ portable

bind ~password ~f t is project (map ~password ~f t).

val iter : password:'k Password.t @ local -> (f:('a -> unit) @ local once portable -> (('a, 'k) t -> unit) @ local once) @ local @@ portable

iter is extract with result type specialized to unit.

val map_shared : 'a 'b 'k. password:'k Password.Shared.t @ local -> (f:('a @ shared -> 'b) @ local once portable -> (('a, 'k) t -> ('b, 'k) t) @ local once) @ local @@ portable

map_shared ~password ~f t applies f to the shared parts of t within the capsule 'k and returns a pointer to the result. Since 'a may have been shared with other threads, 'a must cross portability.

val extract_shared : 'a 'b 'k. password:'k Password.Shared.t @ local -> (f:('a @ shared -> 'b @ unique once portable contended) @ local once portable -> (('a, 'k) t -> 'b @ unique once portable contended) @ local once) @ local @@ portable

extract_shared ~password ~f t applies f to the shared parts of t within the capsule 'k and returns the result. The result is within 'k so must be portable and is marked contended. Since 'a may have been shared with other threads, 'a must cross portability.

module Shared : sig ... end
module Local : sig ... end

Functions to work with ('a, 'k) t @ local.

module Or_null : sig ... end