From 8731cd5b1a290abaeb588da5e0d90d920cd4b4c9 Mon Sep 17 00:00:00 2001 From: "Yang, Longlong" Date: Wed, 20 Dec 2023 01:27:27 -0500 Subject: [PATCH] add active_tasks_count api. currently, executor user can't know how much of tasks are in active state. This patch provide such support. Signed-off-by: Yang, Longlong --- executor/src/executor.rs | 8 ++++++++ executor/src/lib.rs | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/executor/src/executor.rs b/executor/src/executor.rs index cf0cf425..39319b70 100644 --- a/executor/src/executor.rs +++ b/executor/src/executor.rs @@ -121,6 +121,14 @@ impl Executor { tasks.front().is_some() } + + pub fn active_tasks_count(&self) -> usize { + if let Some(tl) = &self.tasks { + tl.len() + } else { + 0 + } + } } pub(crate) static DEFAULT_EXECUTOR: Mutex = Mutex::new(Executor { tasks: None }); diff --git a/executor/src/lib.rs b/executor/src/lib.rs index 68e26b94..743f44d8 100644 --- a/executor/src/lib.rs +++ b/executor/src/lib.rs @@ -38,3 +38,7 @@ where pub fn poll_tasks() -> bool { DEFAULT_EXECUTOR.lock().poll_tasks() } + +pub fn active_tasks_count() -> usize { + DEFAULT_EXECUTOR.lock().active_tasks_count() +}