Sync.RwlockSourceA poisonable and freezable multiple readers, single writer lock that can only be held for a bounded period of time.
k t is the type of a read/write lock protecting the contents of the k capsule.
create k creates a new reader-writer lock for the capsule 'k associated with k, consuming the key itself.
The optional padded argument specifies whether to pad the data structure to avoid false sharing. See Atomic.make for a longer explanation.
Accesswith_access_shared w t ~f acquires t for reading, runs f with shared access to the associated capsule, then releases t. If t is locked for writing then uses w to wait until it is unlocked. The Sync.t is passed to f to allow further use of synchronization primitives.
with_access_shared_freezing w t ~f is with_access_shared w t ~f, but freezes t if f raises an uncaught exception.
try_with_access_shared t ~f attempts to acquire t for reading without blocking. If successful, it runs f as with_access_shared would, but without taking a Sync.t because no waiting is needed. Otherwise, it is Would_block.
try_with_access_shared_freezing t ~f is try_with_access_shared t ~f, but freezes t if f raises an uncaught exception.
with_access_shared_or_cancel w c t ~f is Completed (with_access_shared w t ~f) if c is not canceled, otherwise it is Canceled.
with_access_shared_or_cancel_freezing w c t ~f is with_access_shared_or_cancel w c t ~f, but freezes t if f raises an uncaught exception.
val with_access :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Access.t ->
'a @ unique once portable contended) @ local once) @ local once portable unyielding ->
'a @ unique once portable contendedwith_access w t ~f acquires t for writing, runs f within the associated capsule, then releases t. If t is locked then uses w to wait until it is unlocked. The Sync.t is passed to f to allow further use of synchronization primitives.
val with_access_poisoning :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Access.t ->
'a @ unique once portable contended) @ local once) @ local once portable unyielding ->
'a @ unique once portable contendedwith_access_poisoning w t ~f is with_access w t ~f, but poisons t if f raises an uncaught exception.
val try_with_access :
('a : value_or_null) 'k. 'k t @ local ->
f:
('k Await_sync__.Rwlock.Capsule.Access.t ->
'a @ unique once portable contended) @ local once portable unyielding ->
'a Await_kernel.Or_would_block.t @ unique once portable contendedtry_with_access t ~f attempts to acquire t for writing without blocking. If successful, it runs f as with_access would, but without taking a Sync.t because no waiting is needed. Otherwise, it is Would_block.
val try_with_access_poisoning :
('a : value_or_null) 'k. 'k t @ local ->
f:
('k Await_sync__.Rwlock.Capsule.Access.t ->
'a @ unique once portable contended) @ local once portable unyielding ->
'a Await_kernel.Or_would_block.t @ unique once portable contendedtry_with_access_poisoning t ~f is try_with_access t ~f, but poisons t if f raises an uncaught exception.
val with_access_or_cancel :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Access.t ->
'a @ unique once portable contended) @ local once) @ local once portable unyielding ->
'a Await_kernel.Or_canceled.t @ unique once portable contendedwith_access_or_cancel w c t ~f is Completed (with_access w t ~f) if c is not canceled, otherwise it is Canceled.
val with_access_or_cancel_poisoning :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Access.t ->
'a @ unique once portable contended) @ local once) @ local once portable unyielding ->
'a Await_kernel.Or_canceled.t @ unique once portable contendedwith_access_or_cancel_poisoning w c t ~f is with_access_or_cancel w c t ~f, but poisons t if f raises an uncaught exception.
PasswordPassword.Shared by readerswith_password_shared w t ~f acquires t, runs f with permission to access the associated capsule, then releases t. If t is locked then uses w to wait until it is unlocked. The Sync.t is passed to f to allow further use of synchronization primitives.
with_password_shared_freezing w t ~f is with_password_shared w t ~f, but freezes t if f raises an uncaught exception.
try_with_password_shared t ~f attempts to acquire t for reading without blocking. If successful, it runs f as with_password_shared would, but without taking a Sync.t because no waiting is needed. Otherwise, it is Would_block.
try_with_password_shared_freezing t ~f is try_with_password_shared t ~f, but freezes t if f raises an uncaught exception.
with_password_shared_or_cancel w c t ~f is Completed (with_password_shared w t ~f) if c is not canceled, otherwise it is Canceled.
with_password_shared_or_cancel_freezing w c t ~f is with_password_shared_or_cancel w t ~f, but freezes t if f raises an uncaught exception.
Password for a writerval with_password :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Password.t @ local ->
'a @ unique) @ local once) @ local once unyielding ->
'a @ uniquewith_password w t ~f acquires t, runs f with permission to access the associated capsule, then releases t. If t is locked then uses w to wait until it is unlocked. The Sync.t is passed to f to allow further use of synchronization primitives.
val with_password_poisoning :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Password.t @ local ->
'a @ unique) @ local once) @ local once unyielding ->
'a @ uniquewith_password_poisoning w t ~f is with_password w t ~f, but poisons t if f raises an uncaught exception.
val try_with_password :
('a : value_or_null) 'k. 'k t @ local ->
f:
('k Await_sync__.Rwlock.Capsule.Password.t @ local -> 'a @ unique) @ local once unyielding ->
'a Await_kernel.Or_would_block.t @ uniquetry_with_password t ~f attempts to acquire t for writing without blocking. If successful, it runs f as with_password would, but without taking a Sync.t because no waiting is needed. Otherwise, it is Would_block.
val try_with_password_poisoning :
('a : value_or_null) 'k. 'k t @ local ->
f:
('k Await_sync__.Rwlock.Capsule.Password.t @ local -> 'a @ unique) @ local once unyielding ->
'a Await_kernel.Or_would_block.t @ uniquetry_with_password_poisoning t ~f is try_with_password t ~f, but poisons t if f raises an uncaught exception.
val with_password_or_cancel :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Password.t @ local ->
'a @ unique) @ local once) @ local once unyielding ->
'a Await_kernel.Or_canceled.t @ uniquewith_password_or_cancel w c t ~f is Completed (with_password w t ~f) if c is not canceled, otherwise it is Canceled.
val with_password_or_cancel_poisoning :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Password.t @ local ->
'a @ unique) @ local once) @ local once unyielding ->
'a Await_kernel.Or_canceled.t @ uniquewith_password_or_cancel_poisoning w c t ~f is with_password_or_cancel w c t ~f, but poisons t if f raises an uncaught exception.
Keyval with_key_poisoning :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Key.t @ unique ->
#('a * 'k Await_sync__.Rwlock.Capsule.Key.t) @ unique once) @ local once) @ local once unyielding ->
'a @ unique oncewith_key_poisoning s t ~f locks t for writing and runs f, providing it a key for 'k uniquely. If t is locked for reading or writing, then with_key uses s to wait until it is unlocked. The Sync.t is passed to f to allow further use of synchronization primitives.
There is no non-poisoning version of this function, because you must return the key back (to avoid leaking it via an exception).
val try_with_key_poisoning :
('a : value_or_null) 'k. 'k t @ local ->
f:
('k Await_sync__.Rwlock.Capsule.Key.t @ unique ->
#('a * 'k Await_sync__.Rwlock.Capsule.Key.t) @ unique once) @ local once unyielding ->
'a Await_kernel.Or_would_block.t @ unique oncetry_with_key_poisoning t ~f attempts to acquire t for writing without blocking. If successful, it runs f as with_key_poisoning would, but without taking a Sync.t because no waiting is needed. Otherwise, it is Would_block.
val with_key_or_cancel_poisoning :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Await_sync__.Rwlock.Capsule.Key.t @ unique ->
#('a * 'k Await_sync__.Rwlock.Capsule.Key.t) @ unique once) @ local once) @ local once unyielding ->
'a Await_kernel.Or_canceled.t @ unique oncewith_key_or_cancel_poisoning w c t ~f is with_key_or_cancel w c t ~f, but poisons t if f raises an uncaught exception.
ConditionCondition variable for waiting for changes to state protected by a lock.
val with_key_and_condition_wait_poisoning :
('a : value_or_null) 'k. Await_kernel.Await.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Condition.Wait.t @ local ->
('k Await_sync__.Rwlock.Capsule.Key.t @ unique ->
#('a * 'k Await_sync__.Rwlock.Capsule.Key.t) @ unique once) @ local once) @ local once) @ local once unyielding ->
'a @ unique oncewith_key_and_condition_wait_poisoning w t ~f locks t and runs f, providing it with a key for 'k uniquely and a 'k Condition.Wait.t which provides the ability to temporarily unlock t and wait on an associated 'k Condition.t. Since waiting on a condition variable can delay for an unbounded period of time, this requires an Await.t, even for a Sync mutex, but only passes a Sync.t to the callback. To recover the original Await.t during the execution of f, you can use Condition.Wait.release_temporarily.
The lock is only poisoned if f raises while the lock held; if waiting on a condition variable is terminated or if the callback passed to Condition.Wait.release_temporarily raises, the lock will not be poisoned.
val with_key_and_condition_wait_or_cancel_poisoning :
('a : value_or_null) 'k. Await_kernel.Await.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Condition.Wait.t @ local ->
('k Await_sync__.Rwlock.Capsule.Key.t @ unique ->
#('a * 'k Await_sync__.Rwlock.Capsule.Key.t) @ unique once) @ local once) @ local once) @ local once unyielding ->
'a Await_kernel.Or_canceled.t @ unique oncewith_key_and_condition_wait_or_cancel_poisoining w c t ~f is Completed (with_key_and_condition_wait_poisoining w t ~f) if c is not canceled, otherwise it is Canceled.
val poison :
'k t @ local ->
'k Await_sync__.Rwlock.Capsule.Key.t @ unique ->
'k Await_sync__.Rwlock.Capsule.Key.t @ uniquepoison t key poisons the rwlock associated with the key.
Note that poisoning a rwlock does not signal waiters on associated condition variables.
is_poisoned t is true if the reader-writer lock t is poisoned.