From 6ffbd15a34a4d60cf9a3a753d00794b3896a477b Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 2 Jun 2023 12:05:39 -0400 Subject: [PATCH] add Pool.size --- moonpool.opam | 2 +- src/pool.ml | 1 + src/pool.mli | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/moonpool.opam b/moonpool.opam index 23ff8e1a..69f53216 100644 --- a/moonpool.opam +++ b/moonpool.opam @@ -11,8 +11,8 @@ depends: [ "ocaml" {>= "4.08"} "dune" {>= "3.0"} "either" - "mdx" {>= "1.9.0" & with-test} "odoc" {with-doc} + "mdx" {>= "1.9.0" & with-test} ] build: [ ["dune" "subst"] {dev} diff --git a/src/pool.ml b/src/pool.ml index b1d744ba..8e22f664 100644 --- a/src/pool.ml +++ b/src/pool.ml @@ -22,6 +22,7 @@ let add_global_thread_loop_wrapper f : unit = done let[@inline] run self f : unit = S_queue.push self.q f +let size self = Array.length self.threads let worker_thread_ ~on_exn (active : bool A.t) (q : _ S_queue.t) : unit = while A.get active do diff --git a/src/pool.mli b/src/pool.mli index 6a04a57f..b5676d4a 100644 --- a/src/pool.mli +++ b/src/pool.mli @@ -33,6 +33,9 @@ val create : to use for this pool's workers. *) +val size : t -> int +(** Number of threads *) + val shutdown : t -> unit (** Shutdown the pool and wait for it to terminate. Idempotent. *)