Module Rwlock.Guard

type 'k t

'k Rwlock.Guard.t represents a reader-writer lock that is locked exclusively for writing. It morally contains a Capsule.Key.t, but also has a finalizer that poisons the lock if the guard is garbage collected without being passed to Guard.release.

val with_key : 'a 'k. 'k t @ unique -> (f: ('k Capsule.Key.t @ unique -> #('a * 'k Capsule.Key.t) @ unique once) @ local once -> 'a * 'k t @ unique once) @ once

with_key t ~f runs f, providing it a key for 'k uniquely.

val with_password : 'a 'k. 'k t @ unique -> (f:('k Capsule.Password.t @ local -> 'a @ unique) @ local once -> 'a * 'k t @ unique) @ once

with_password g ~f runs f, providing it a password for 'k, and returns the result of f together with the guard.

val access : 'a 'k. 'k t @ unique -> (f: ('k Capsule.Access.t -> 'a @ unique once portable contended) @ local once portable -> 'a * 'k t @ unique once portable contended) @ once

access g ~f runs f, providing it access to the capsule 'k, and returns the result of f together with the guard.

val release : 'k t @ unique -> unit

release guard releases the lock protected by guard, consuming the guard.

val poison : 'k t @ unique -> 'k Capsule.Key.t @ unique

poison guard poisons the lock protected by guard, consuming the guard and returning the key to the protected capsule.

val downgrade : 'k t @ unique -> 'k Shared_guard.t @ unique

downgrade guard downgrades the write guard guard to a read guard.