Module CCLock
Utils around Mutex
A value wrapped into a Mutex, for more safety.
- since
- 0.8
val create : 'a -> 'a t
Create a new protected value.
val with_lock : 'a t -> ('a -> 'b) -> 'b
with_lock l f
runsf x
wherex
is the value protected with the lockl
, in a critical section. Iff x
fails,with_lock l f
fails too but the lock is released.
val try_with_lock : 'a t -> ('a -> 'b) -> 'b option
try_with_lock l f
runsf x
in a critical section ifl
is not locked.x
is the value protected by the lockl
. Iff x
fails,try_with_lock l f
fails too but the lock is released.- since
- 0.22
module LockRef : sig ... end
Type allowing to manipulate the lock as a reference.
val with_lock_as_ref : 'a t -> f:('a LockRef.t -> 'b) -> 'b
with_lock_as_ref l f
callsf
with a reference-like object that allows to manipulate the value ofl
safely. The object passed tof
must not escape the function call.- since
- 0.13
val update : 'a t -> ('a -> 'a) -> unit
update l f
replaces the contentx
ofl
withf x
, atomically.
val update_map : 'a t -> ('a -> 'a * 'b) -> 'b
update_map l f
computesx', y = f (get l)
, then putsx'
inl
and returnsy
.- since
- 0.16
val mutex : _ t -> Mutex.t
Underlying mutex.
val get : 'a t -> 'a
Atomically get the value in the lock. The value that is returned isn't protected!
val set : 'a t -> 'a -> unit
Atomically set the value.
- since
- 0.13
val incr : int t -> unit
Atomically increment the value.
- since
- 0.13
val decr : int t -> unit
Atomically decrement the value.
- since
- 0.13
val incr_then_get : int t -> int
incr_then_get x
incrementsx
, and returns its new value.- since
- 0.16
val get_then_incr : int t -> int
get_then_incr x
incrementsx
, and returns its previous value.- since
- 0.16
val decr_then_get : int t -> int
decr_then_get x
decrementsx
, and returns its new value.- since
- 0.16
val get_then_decr : int t -> int
get_then_decr x
decrementsx
, and returns its previous value.- since
- 0.16
val get_then_set : bool t -> bool
get_then_set b
setsb
totrue
, and returns the old value.- since
- 0.16
val get_then_clear : bool t -> bool
get_then_clear b
setsb
tofalse
, and returns the old value.- since
- 0.16