mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
small fixes in CCSemaphore
This commit is contained in:
parent
d3464563c1
commit
483f90cb52
2 changed files with 8 additions and 7 deletions
|
|
@ -6,11 +6,12 @@ type t = {
|
||||||
cond : Condition.t;
|
cond : Condition.t;
|
||||||
}
|
}
|
||||||
|
|
||||||
let create n = {
|
let create n =
|
||||||
n;
|
if n <= 0 then invalid_arg "Semaphore.create";
|
||||||
mutex=Mutex.create();
|
{ n;
|
||||||
cond=Condition.create();
|
mutex=Mutex.create();
|
||||||
}
|
cond=Condition.create();
|
||||||
|
}
|
||||||
|
|
||||||
let get t = t.n
|
let get t = t.n
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,13 @@ type t
|
||||||
|
|
||||||
val create : int -> t
|
val create : int -> t
|
||||||
(** [create n] creates a semaphore with initial value [n]
|
(** [create n] creates a semaphore with initial value [n]
|
||||||
@raise Invalid_argument if [n < 0] *)
|
@raise Invalid_argument if [n <= 0] *)
|
||||||
|
|
||||||
val get : t -> int
|
val get : t -> int
|
||||||
(** Current value *)
|
(** Current value *)
|
||||||
|
|
||||||
val acquire : int -> t -> unit
|
val acquire : int -> t -> unit
|
||||||
(** [acquire n s] blocks until [get s > n], then atomically
|
(** [acquire n s] blocks until [get s >= n], then atomically
|
||||||
sets [s := !s - n] *)
|
sets [s := !s - n] *)
|
||||||
|
|
||||||
val release : int -> t -> unit
|
val release : int -> t -> unit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue