From 563c355131350b4c8a9439c8803f63b08d5f0c1e Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 13 Sep 2026 01:47:02 +1000 Subject: [PATCH] TaskQueue: Add GetOutstandingTasks() and ExecuteOneTask() --- src/common/task_queue.cpp | 16 ++++++++++++++++ src/common/task_queue.h | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/src/common/task_queue.cpp b/src/common/task_queue.cpp index 2478208a9..82294fd39 100644 --- a/src/common/task_queue.cpp +++ b/src/common/task_queue.cpp @@ -40,6 +40,12 @@ void TaskQueue::SetWorkerCount(u32 count) } } +size_t TaskQueue::GetOutstandingTasks() +{ + std::unique_lock lock(m_mutex); + return m_tasks_outstanding; +} + void TaskQueue::SubmitTask(TaskFunctionType func) { std::unique_lock lock(m_mutex); @@ -76,6 +82,16 @@ void TaskQueue::WaitForAll(std::unique_lock& lock) }); } +bool TaskQueue::ExecuteOneTask() +{ + std::unique_lock lock(m_mutex); + if (m_tasks.empty()) + return false; + + ExecuteOneTask(lock); + return true; +} + void TaskQueue::ExecuteOneTask(std::unique_lock& lock) { TaskFunctionType func = std::move(m_tasks.front()); diff --git a/src/common/task_queue.h b/src/common/task_queue.h index 6220b4659..fa5762fc3 100644 --- a/src/common/task_queue.h +++ b/src/common/task_queue.h @@ -28,6 +28,9 @@ public: /// @param count The desired number of worker threads. void SetWorkerCount(u32 count); + /// Returns the number of tasks remaining. + size_t GetOutstandingTasks(); + /// Submits a task to the queue for execution. /// @param func The task function to execute. void SubmitTask(TaskFunctionType func); @@ -35,6 +38,10 @@ public: /// Waits for all submitted tasks to complete execution. void WaitForAll(); + /// Executes a single task on the calling thread. + /// Returns false if there was no work to complete. + bool ExecuteOneTask(); + private: /// Waits for all submitted tasks to complete execution. /// This is a helper function that assumes a lock is already held.