TaskQueue: Add GetOutstandingTasks() and ExecuteOneTask()

pull/3797/merge
Stenzek 2 weeks ago
parent e26fa60915
commit 563c355131
No known key found for this signature in database

@ -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<std::mutex>& 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<std::mutex>& lock)
{
TaskFunctionType func = std::move(m_tasks.front());

@ -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.

Loading…
Cancel
Save