Module CCLock
Utils around Mutex
A value wrapped into a Mutex, for more safety.
- since
 - 0.8
 
val create : 'a -> 'a tCreate a new protected value.
val with_lock : 'a t -> ('a -> 'b) -> 'bwith_lock l frunsf xwherexis the value protected with the lockl, in a critical section. Iff xfails,with_lock l ffails too but the lock is released.
val try_with_lock : 'a t -> ('a -> 'b) -> 'b optiontry_with_lock l frunsf xin a critical section iflis not locked.xis the value protected by the lockl. Iff xfails,try_with_lock l ffails too but the lock is released.- since
 - 0.22
 
module LockRef : sig ... endType allowing to manipulate the lock as a reference.
val with_lock_as_ref : 'a t -> f:('a LockRef.t -> 'b) -> 'bwith_lock_as_ref l fcallsfwith a reference-like object that allows to manipulate the value oflsafely. The object passed tofmust not escape the function call.- since
 - 0.13
 
val update : 'a t -> ('a -> 'a) -> unitupdate l freplaces the contentxoflwithf x, atomically.
val update_map : 'a t -> ('a -> 'a * 'b) -> 'bupdate_map l fcomputesx', y = f (get l), then putsx'inland returnsy.- since
 - 0.16
 
val mutex : _ t -> Mutex.tUnderlying mutex.
val get : 'a t -> 'aAtomically get the value in the lock. The value that is returned isn't protected!
val set : 'a t -> 'a -> unitAtomically set the value.
- since
 - 0.13
 
val incr : int t -> unitAtomically increment the value.
- since
 - 0.13
 
val decr : int t -> unitAtomically decrement the value.
- since
 - 0.13
 
val incr_then_get : int t -> intincr_then_get xincrementsx, and returns its new value.- since
 - 0.16
 
val get_then_incr : int t -> intget_then_incr xincrementsx, and returns its previous value.- since
 - 0.16
 
val decr_then_get : int t -> intdecr_then_get xdecrementsx, and returns its new value.- since
 - 0.16
 
val get_then_decr : int t -> intget_then_decr xdecrementsx, and returns its previous value.- since
 - 0.16
 
val get_then_set : bool t -> boolget_then_set bsetsbtotrue, and returns the old value.- since
 - 0.16
 
val get_then_clear : bool t -> boolget_then_clear bsetsbtofalse, and returns the old value.- since
 - 0.16