mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-10 13:13:56 -05:00
remove PARAM.min_size in CCPool
This commit is contained in:
parent
0e26502008
commit
282f85a874
2 changed files with 5 additions and 18 deletions
|
|
@ -9,9 +9,6 @@ type +'a state =
|
||||||
| Failed of exn
|
| Failed of exn
|
||||||
|
|
||||||
module type PARAM = sig
|
module type PARAM = sig
|
||||||
val min_size : int
|
|
||||||
(** Minimum number of threads in the pool *)
|
|
||||||
|
|
||||||
val max_size : int
|
val max_size : int
|
||||||
(** Maximum number of threads in the pool *)
|
(** Maximum number of threads in the pool *)
|
||||||
end
|
end
|
||||||
|
|
@ -19,8 +16,8 @@ end
|
||||||
exception Stopped
|
exception Stopped
|
||||||
|
|
||||||
(*$inject
|
(*$inject
|
||||||
module P = Make(struct let min_size = 0 let max_size = 30 end)
|
module P = Make(struct let max_size = 30 end)
|
||||||
module P2 = Make(struct let min_size = 1 let max_size = 15 end)
|
module P2 = Make(struct let max_size = 15 end)
|
||||||
module Fut = P.Fut
|
module Fut = P.Fut
|
||||||
module Fut2 = P2.Fut
|
module Fut2 = P2.Fut
|
||||||
*)
|
*)
|
||||||
|
|
@ -82,11 +79,10 @@ module Make(P : PARAM) = struct
|
||||||
(* thread: seek what to do next (including dying).
|
(* thread: seek what to do next (including dying).
|
||||||
Assumes the pool is locked. *)
|
Assumes the pool is locked. *)
|
||||||
let get_next_ pool =
|
let get_next_ pool =
|
||||||
(*Printf.printf "get_next (cur=%d, min=%d, idle=%d, stop=%B)\n%!" pool.cur_size P.min_size pool.cur_idle pool.stop;*)
|
(*Printf.printf "get_next (cur=%d, idle=%d, stop=%B)\n%!" pool.cur_size pool.cur_idle pool.stop;*)
|
||||||
if pool.stop || (Queue.is_empty pool.jobs && pool.cur_size > P.min_size) then (
|
if pool.stop || (Queue.is_empty pool.jobs && pool.cur_size > 0) then (
|
||||||
(* die: the thread would be idle otherwise *)
|
(* die: the thread would be idle otherwise *)
|
||||||
assert (pool.cur_size > 0);
|
(*Printf.printf "time… to die (cur=%d, idle=%d, stop=%B)\n%!" pool.cur_size pool.cur_idle pool.stop;*)
|
||||||
(*Printf.printf "time… to die (cur=%d, min=%d, idle=%d, stop=%B)\n%!" pool.cur_size P.min_size pool.cur_idle pool.stop;*)
|
|
||||||
decr_size_ pool;
|
decr_size_ pool;
|
||||||
Die
|
Die
|
||||||
) else if Queue.is_empty pool.jobs then (
|
) else if Queue.is_empty pool.jobs then (
|
||||||
|
|
@ -129,12 +125,6 @@ module Make(P : PARAM) = struct
|
||||||
incr_size_ pool;
|
incr_size_ pool;
|
||||||
ignore (Thread.create serve pool))
|
ignore (Thread.create serve pool))
|
||||||
|
|
||||||
(* launch the minimum required number of threads *)
|
|
||||||
let () =
|
|
||||||
if P.min_size < 0 then invalid_arg "CCPool: min_size must be >= 0";
|
|
||||||
if P.min_size > P.max_size then invalid_arg "CCPool: min_size must be <= max_size";
|
|
||||||
for _i = 1 to P.min_size do launch_worker_ pool done
|
|
||||||
|
|
||||||
(* heuristic criterion for starting a new thread. *)
|
(* heuristic criterion for starting a new thread. *)
|
||||||
let can_start_thread_ p = p.cur_size < P.max_size
|
let can_start_thread_ p = p.cur_size < P.max_size
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,6 @@ type +'a state =
|
||||||
| Failed of exn
|
| Failed of exn
|
||||||
|
|
||||||
module type PARAM = sig
|
module type PARAM = sig
|
||||||
val min_size : int
|
|
||||||
(** Minimum number of threads in the pool *)
|
|
||||||
|
|
||||||
val max_size : int
|
val max_size : int
|
||||||
(** Maximum number of threads in the pool *)
|
(** Maximum number of threads in the pool *)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue