Sync.MutexSourceA poisonable mutual exclusion lock.
Mutexes that can only be held for a bounded period of time
k t is the type of a mutex protecting the contents of the k capsule which can only be held for a bounded period of time.
create k creates a new mutex 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.
Accessval with_access :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Capsule.Prim.Access.t ->
'a @ unique once portable contended) @ local once) @ local once portable unyielding ->
'a @ unique once portable contended @@ portablewith_access s t ~f acquires t, runs f within the associated capsule, then releases t. If t is locked then uses s to wait until it is unlocked. The Sync.t is passed to f to allow further use of synchronization primitives.
val try_with_access :
('a : value_or_null) 'k. 'k t @ local ->
f:
('k Capsule.Prim.Access.t -> 'a @ unique once portable contended) @ local once portable unyielding ->
'a Await_kernel.Or_would_block.t @ unique once portable contended @@ portabletry_with_access t ~f is like with_access, but returns Would_block if t is currently locked.
val with_access_poisoning :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Capsule.Prim.Access.t ->
'a @ unique once portable contended) @ local once) @ local once portable unyielding ->
'a @ unique once portable contended @@ portablewith_access_poisoning s t ~f acquires t, runs f within the associated capsule, then releases t. If t is locked then uses s to wait until it is unlocked. The Sync.t is passed to f to allow further use of synchronization primitives.
Poisons t if f raises an uncaught exception.
val try_with_access_poisoning :
('a : value_or_null) 'k. 'k t @ local ->
f:
('k Capsule.Prim.Access.t -> 'a @ unique once portable contended) @ local once portable unyielding ->
'a Await_kernel.Or_would_block.t @ unique once portable contended @@ portabletry_with_access_poisoning t ~f is like with_access_poisoning, but returns Would_block if t is currently locked.
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 Capsule.Prim.Access.t ->
'a @ unique once portable contended) @ local once) @ local once portable unyielding ->
'a Await_kernel.Or_canceled.t @ unique once portable contended @@ portablewith_access_or_cancel s c t f is Completed (with_access s 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 Capsule.Prim.Access.t ->
'a @ unique once portable contended) @ local once) @ local once portable unyielding ->
'a Await_kernel.Or_canceled.t @ unique once portable contended @@ portablewith_access_or_cancel_poisoning s c t f is Completed (with_access_poisoning s t f) if c is not canceled, otherwise it is Canceled.
Poisons t if f raises an uncaught exception.
Passwordval with_password :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Capsule.Prim.Password.t @ local ->
'a @ unique) @ local once) @ local once unyielding ->
'a @ unique @@ portablewith_password s t f acquires t, runs f with permission to access the associated capsule, then releases t. If t is locked then uses s to wait until it is unlocked. The Sync.t is passed to f to allow further use of synchronization primitives.
val try_with_password :
('a : value_or_null) 'k. 'k t @ local ->
f:('k Capsule.Prim.Password.t @ local -> 'a @ unique) @ local once unyielding ->
'a Await_kernel.Or_would_block.t @ unique @@ portabletry_with_password t ~f is like with_password, but returns Would_block if t is currently locked.
val with_password_poisoning :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
f:
(Await_kernel.Sync.t @ local ->
('k Capsule.Prim.Password.t @ local ->
'a @ unique) @ local once) @ local once unyielding ->
'a @ unique @@ portablewith_password_poisoning s t f acquires t, runs f with permission to access the associated capsule, then releases t. If t is locked then uses s to wait until it is unlocked. The Sync.t is passed to f to allow further use of synchronization primitives.
Poisons t if f raises an exception.
val try_with_password_poisoning :
('a : value_or_null) 'k. 'k t @ local ->
f:('k Capsule.Prim.Password.t @ local -> 'a @ unique) @ local once unyielding ->
'a Await_kernel.Or_would_block.t @ unique @@ portabletry_with_password_poisoning t ~f is like with_password_poisoning, but returns Would_block if t is currently locked.
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 Capsule.Prim.Password.t @ local ->
'a @ unique) @ local once) @ local once unyielding ->
'a Await_kernel.Or_canceled.t @ unique @@ portablewith_password_or_cancel s c t f is Completed (with_password s 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 Capsule.Prim.Password.t @ local ->
'a @ unique) @ local once) @ local once unyielding ->
'a Await_kernel.Or_canceled.t @ unique @@ portablewith_password_or_cancel_poisoning s c t f is Completed (with_password_poisoning s t f) if c is not canceled, otherwise it is Canceled.
Poisons t if f raises an 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 Capsule.Prim.Key.t @ unique ->
#('a * 'k Capsule.Prim.Key.t) @ unique once) @ local once) @ local once unyielding ->
'a @ unique once @@ portablewith_key_poisoning s t ~f locks t and runs f, providing it a key for 'k uniquely. If the function raises without returning the key back, the mutex is poisoned. If t is locked, then with_key_poisoning 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 Capsule.Prim.Key.t @ unique ->
#('a * 'k Capsule.Prim.Key.t) @ unique once) @ local once unyielding ->
'a Await_kernel.Or_would_block.t @ unique once @@ portabletry_with_key t ~f is like with_key, but returns Would_block if t is currently locked.
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 Capsule.Prim.Key.t @ unique ->
#('a * 'k Capsule.Prim.Key.t) @ unique once) @ local once) @ local once unyielding ->
'a Await_kernel.Or_canceled.t @ unique once @@ portablewith_key_or_cancel_poisoning s c t ~f is Completed (with_key_poisoning s t ~f) if c is not canceled, otherwise it is Canceled.
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 Capsule.Prim.Key.t @ unique ->
#('a * 'k Capsule.Prim.Key.t) @ unique once) @ local once) @ local once) @ local once unyielding ->
'a @ unique once @@ portablewith_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 Capsule.Prim.Key.t @ unique ->
#('a * 'k Capsule.Prim.Key.t) @ unique once) @ local once) @ local once) @ local once unyielding ->
'a Await_kernel.Or_canceled.t @ unique once @@ portablewith_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 release_temporarily :
('a : value_or_null) 'k. Await_kernel.Sync.t @ local ->
'k t @ local ->
'k Capsule.Prim.Key.t @ unique ->
f:(unit -> 'a @ unique) @ local once ->
#('a * 'k Capsule.Prim.Key.t) @ unique @@ portablerelease_temporarily s t k ~f releases t, runs f without the mutex, reacquires t and returns the result of running f along with the k.
To obtain a key to pass to release_temporarily, use with_key or similar functions.
val release_temporarily_or_cancel :
('a : value_or_null). Await_kernel.Sync.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
'k Capsule.Prim.Key.t @ unique ->
f:(unit -> 'a @ unique) @ local once unyielding ->
#('a * 'k Capsule.Prim.Key.t)
Await_kernel.Or_canceled.t__'value_or_null_void' @ unique @@ portablerelease_temporarily_or_cancel s c t k ~f is Completed (release_temporarily s t k ~f) if c is not canceled, otherwise it is Canceled.
val poison :
'k t @ local ->
'k Capsule.Prim.Key.t @ unique ->
'k Capsule.Prim.Key.t @ unique @@ portablepoison t key poisons the mutex associated with the key.
val acquire_and_poison :
Await_kernel.Sync.t @ local ->
'k t @ local ->
'k Capsule.Prim.Key.t @ unique @@ portableacquire_and_poison s t acquires t and then immediately poisons it, returning the key to the protected capsule.
val acquire_and_poison_or_cancel :
Await_kernel.Sync.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
'k Capsule.Prim.Key.t Await_kernel.Or_canceled.t__void @ unique @@ portableacquire_and_poison_or_cancel s c t is Completed (acquire_and_poison s t) if c is not canceled, otherwise it is Canceled.
is_poisoned t determines whether the mutex t is poisoned.
is_locked t determines whether the mutex t is locked.
poison_unacquired t poisons t without acquiring it. Does nothing if t is already poisoned.
Note that this can render the capsule associated with t innaccessible, since it potentially destroys the associated key.