Module Await_capsule.With_rwlock

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

An 'a Capsule.With_rwlock.t is a value of type 'a in its own capsule, protected by a reader-writer lock

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

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

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

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

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

with_write t ~f locks the reader-writer lock associated with t for writing and calls f on the protected value, returning the result.

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

with_read t ~f locks the reader-writer lock associated with t for reading and calls f on the protected value, returning the result.

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

iter_write t ~f is with_write t ~f, specialised to a function that returns unit

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

iter_read t ~f is with_read t ~f, specialised to a function that returns unit