mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
labels in cclock
This commit is contained in:
parent
3c233d9cf3
commit
dc896e3bbb
2 changed files with 3 additions and 3 deletions
|
|
@ -66,7 +66,7 @@ module LockRef = struct
|
||||||
let update t f = t.content <- f t.content
|
let update t f = t.content <- f t.content
|
||||||
end
|
end
|
||||||
|
|
||||||
let with_lock_as_ref l f =
|
let with_lock_as_ref l ~f =
|
||||||
Mutex.lock l.mutex;
|
Mutex.lock l.mutex;
|
||||||
try
|
try
|
||||||
let x = f l in
|
let x = f l in
|
||||||
|
|
@ -80,7 +80,7 @@ let with_lock_as_ref l f =
|
||||||
let l = create 0 in
|
let l = create 0 in
|
||||||
let test_it l =
|
let test_it l =
|
||||||
with_lock_as_ref l
|
with_lock_as_ref l
|
||||||
(fun r ->
|
~f:(fun r ->
|
||||||
let x = LockRef.get r in
|
let x = LockRef.get r in
|
||||||
LockRef.set r (x+10);
|
LockRef.set r (x+10);
|
||||||
Thread.yield ();
|
Thread.yield ();
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ module LockRef : sig
|
||||||
val update : 'a t -> ('a -> 'a) -> unit
|
val update : 'a t -> ('a -> 'a) -> unit
|
||||||
end
|
end
|
||||||
|
|
||||||
val with_lock_as_ref : 'a t -> ('a LockRef.t -> 'b) -> 'b
|
val with_lock_as_ref : 'a t -> f:('a LockRef.t -> 'b) -> 'b
|
||||||
(** [with_lock_as_ref l f] calls [f] with a reference-like object
|
(** [with_lock_as_ref l f] calls [f] with a reference-like object
|
||||||
that allows to manipulate the value of [l] safely.
|
that allows to manipulate the value of [l] safely.
|
||||||
The object passed to [f] must not escape the function call
|
The object passed to [f] must not escape the function call
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue