Added getActiveTasks() function to count how many tasks are running or suspended.

This commit is contained in:
2023-12-07 17:14:45 +01:00
parent 5e236dae00
commit 0e877f4769
2 changed files with 15 additions and 0 deletions

View File

@@ -174,6 +174,20 @@ void SimpleTaskLoop::addStoredTask(StoredTask&& storedTask) noexcept
}
}
std::size_t SimpleTaskLoop::getActiveTasks() const noexcept
{
std::size_t sum = 0;
for (const StoredTask& task : mijin::chain(tasks_, newTasks_))
{
const TaskStatus status = task.task ? task.task->status() : TaskStatus::FINISHED;
if (status == TaskStatus::SUSPENDED || status == TaskStatus::RUNNING)
{
++sum;
}
}
return sum;
}
void MultiThreadedTaskLoop::transferCurrentTask(TaskLoop& otherLoop) noexcept
{
if (&otherLoop == this) {