Added getActiveTasks() function to count how many tasks are running or suspended.
This commit is contained in:
parent
5e236dae00
commit
0e877f4769
@ -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
|
void MultiThreadedTaskLoop::transferCurrentTask(TaskLoop& otherLoop) noexcept
|
||||||
{
|
{
|
||||||
if (&otherLoop == this) {
|
if (&otherLoop == this) {
|
||||||
|
@ -542,6 +542,7 @@ public: // TaskLoop implementation
|
|||||||
public: // public interface
|
public: // public interface
|
||||||
[[nodiscard]] constexpr bool empty() const noexcept { return tasks_.empty() && newTasks_.empty(); }
|
[[nodiscard]] constexpr bool empty() const noexcept { return tasks_.empty() && newTasks_.empty(); }
|
||||||
[[nodiscard]] constexpr std::size_t getNumTasks() const noexcept { return tasks_.size() + newTasks_.size(); }
|
[[nodiscard]] constexpr std::size_t getNumTasks() const noexcept { return tasks_.size() + newTasks_.size(); }
|
||||||
|
[[nodiscard]] std::size_t getActiveTasks() const noexcept;
|
||||||
inline CanContinue tick();
|
inline CanContinue tick();
|
||||||
inline void runUntilDone(IgnoreWaiting ignoreWaiting = IgnoreWaiting::NO);
|
inline void runUntilDone(IgnoreWaiting ignoreWaiting = IgnoreWaiting::NO);
|
||||||
inline void cancelAllTasks() noexcept;
|
inline void cancelAllTasks() noexcept;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user