Module Await_capsule.With_mutex

type ('a, 'k) inner = {
  1. data : ('a, 'k) Portable_kernel.Capsule.Data.t;
  2. mutex : 'k Mutex.t;
}
type 'a t =
  1. | P : ('a, 'k) inner -> 'a t

An 'a Capsule.With_mutex.t is a value of type 'a in its own capsule, protected by a mutex

val create : (Base.unit -> 'a) @ local once portable -> 'a t

create f runs f within a fresh capsule, and creates a Capsule.With_mutex.t containing the result

val of_isolated : 'a Portable_kernel.Capsule.Isolated.t @ unique -> 'a t

of_isolated isolated creates a Capsule.With_mutex.t from a value in an isolated capsule, consuming the isolated capsule.

val with_lock : 'a 'b. Await_kernel.Await.t @ local -> ('a t -> (f:('a -> 'b @ portable contended) @ local once portable -> 'b @ portable contended) @ local) @ local

with_lock t ~f locks the mutex associated with t and calls f on the protected value, returning the result.

val iter : Await_kernel.Await.t @ local -> ('a t -> (f:('a -> Base.unit) @ local once portable -> Base.unit) @ local) @ local

iter t ~f is with_lock t ~f, specialised to a function that returns unit

val map : Await_kernel.Await.t @ local -> ('a t -> (f:('a -> 'b) @ local once portable -> 'b t) @ local) @ local

map t ~f locks the mutex associated with t and calls f on the protected value, returning a new With_mutex.t containing the result in the same capsule, and protected by the same mutex.

val destroy : Await_kernel.Await.t @ local -> ('a t -> 'a) @ local

destroy t poisons the mutex associated with t, merging the protected value into the current capsule and returning it.