diff --git a/src/pool.ml b/src/pool.ml index 8cb1912e..87257f7d 100644 --- a/src/pool.ml +++ b/src/pool.ml @@ -51,7 +51,12 @@ let run (self : t) (f : task) : unit = | Exit -> () | Bb_queue.Closed -> raise Shutdown -let size self = Array.length self.threads +let[@inline] size self = Array.length self.threads + +let num_tasks (self : t) : int = + let n = ref 0 in + Array.iter (fun q -> n := !n + Bb_queue.size q) self.qs; + !n exception Got_task of task diff --git a/src/pool.mli b/src/pool.mli index d2e8a72c..3fc6c983 100644 --- a/src/pool.mli +++ b/src/pool.mli @@ -52,6 +52,11 @@ val create : val size : t -> int (** Number of threads *) +val num_tasks : t -> int +(** Current number of tasks. This is at best a snapshot, useful for metrics + and debugging. + @since 0.2 *) + val shutdown : t -> unit (** Shutdown the pool and wait for it to terminate. Idempotent. *)