Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
add active_tasks_count api.
Browse files Browse the repository at this point in the history
currently, executor user can't know how much of tasks
are in active state.
This patch provide such support.

Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang committed Dec 20, 2023
1 parent 7d5d9dc commit 8731cd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Executor> = Mutex::new(Executor { tasks: None });
4 changes: 4 additions & 0 deletions executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 8731cd5

Please sign in to comment.