small fixes in CCSemaphore

This commit is contained in:
Simon Cruanes 2016-01-25 14:26:30 +01:00
parent d3464563c1
commit 483f90cb52
2 changed files with 8 additions and 7 deletions

View file

@ -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

View file

@ -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