Await.MutexSourceA poisonable mutual exclusion lock.
Mutexes that can be held for an unbounded period of time
k t is the type of a mutex protecting the contents of the k capsule, which can be held for an unbounded 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.Await.t @ local ->
'k t @ local ->
f:
('k Capsule.Prim.Access.t -> 'a @ unique once portable contended) @ local once portable ->
'a @ unique once portable contended @@ portablewith_access w t ~f acquires t, runs f within the associated capsule, then releases t. If t is locked then uses w to wait until it is unlocked.
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 ->
'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.Await.t @ local ->
'k t @ local ->
f:
('k Capsule.Prim.Access.t -> 'a @ unique once portable contended) @ local once portable ->
'a @ unique once portable contended @@ portablewith_access_poisoning w t ~f acquires t, runs f within the associated capsule, then releases t. If t is locked then uses w to wait until it is unlocked.
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 ->
'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.Await.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:
('k Capsule.Prim.Access.t -> 'a @ unique once portable contended) @ local once portable ->
'a Await_kernel.Or_canceled.t @ unique once portable contended @@ portablewith_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.Await.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:
('k Capsule.Prim.Access.t -> 'a @ unique once portable contended) @ local once portable ->
'a Await_kernel.Or_canceled.t @ unique once portable contended @@ portablewith_access_or_cancel_poisoning w c t f is Completed (with_access_poisoning w 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.Await.t @ local ->
'k t @ local ->
f:('k Capsule.Prim.Password.t @ local -> 'a @ unique) @ local once ->
'a @ unique @@ portablewith_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.
val try_with_password :
('a : value_or_null) 'k. 'k t @ local ->
f:('k Capsule.Prim.Password.t @ local -> 'a @ unique) @ local once ->
'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.Await.t @ local ->
'k t @ local ->
f:('k Capsule.Prim.Password.t @ local -> 'a @ unique) @ local once ->
'a @ unique @@ portablewith_password_poisoning 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.
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 ->
'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.Await.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:('k Capsule.Prim.Password.t @ local -> 'a @ unique) @ local once ->
'a Await_kernel.Or_canceled.t @ unique @@ portablewith_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.Await.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:('k Capsule.Prim.Password.t @ local -> 'a @ unique) @ local once ->
'a Await_kernel.Or_canceled.t @ unique @@ portablewith_password_or_cancel_poisoning w c t f is Completed (with_password_poisoning w 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.Await.t @ local ->
'k t @ local ->
f:
('k Capsule.Prim.Key.t @ unique ->
#('a * 'k Capsule.Prim.Key.t) @ unique once) @ local once ->
'a @ unique once @@ portablewith_key_poisoning 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 w to wait until it is unlocked.
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 ->
'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.Await.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
f:
('k Capsule.Prim.Key.t @ unique ->
#('a * 'k Capsule.Prim.Key.t) @ unique once) @ local once ->
'a Await_kernel.Or_canceled.t @ unique once @@ portablewith_key_or_cancel_poisoning w c t ~f is Completed (with_key_poisoning w 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:
('k Condition.Wait.t @ local ->
('k Capsule.Prim.Key.t @ unique ->
#('a * 'k Capsule.Prim.Key.t) @ unique once) @ local once) @ local once ->
'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.
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:
('k Condition.Wait.t @ local ->
('k Capsule.Prim.Key.t @ unique ->
#('a * 'k Capsule.Prim.Key.t) @ unique once) @ local once) @ local once ->
'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.Await.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 w 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.Await.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t @ local ->
'k Capsule.Prim.Key.t @ unique ->
f:(unit -> 'a @ unique) @ local once ->
#('a * 'k Capsule.Prim.Key.t)
Await_kernel.Or_canceled.t__'value_or_null_void' @ unique @@ portablerelease_temporarily_or_cancel w c t k ~f is Completed (release_temporarily w 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.
Note that poisoning a mutex does not signal waiters on associated condition variables.
val acquire_and_poison :
Await_kernel.Await.t @ local ->
'k t @ local ->
'k Capsule.Prim.Key.t @ unique @@ portableacquire_and_poison w t acquires t and then immediately poisons it, returning the key to the protected capsule.
val acquire_and_poison_or_cancel :
Await_kernel.Await.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 w c t is Completed (acquire_and_poison w t) if c is not canceled, otherwise it is Canceled.
acquire w t acquires t and returns a guard for the locked mutex. If t is locked, then acquire uses w to wait until it is unlocked.
val acquire_or_cancel :
Await_kernel.Await.t @ local ->
Await_kernel.Cancellation.t @ local ->
'k t ->
'k Guard.t Await_kernel.Or_canceled.t @ unique @@ portableacquire_or_cancel w c t is Completed (acquire w t) if c is not canceled, otherwise it is Canceled.
try_acquire t is like acquire, but returns Would_block if t is currently locked.
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.
Note that poisoning a mutex does not signal waiters on associated condition variables.
A poisonable single word mutual exclusion lock embedded within an atomic location.