Radium Engine
1.5.20
|
This class allows tasks to be registered and then executed in parallel on separate threads. More...
#include <Core/Tasks/TaskQueue.hpp>
Classes | |
struct | TimerData |
Record of a task's start and end time. More... | |
Public Types | |
using | TaskId = Utils::Index |
Identifier for a task in the task queue. | |
Public Member Functions | |
TaskQueue (uint numThreads) | |
~TaskQueue () | |
Destructor. Waits for all the threads and safely deletes them. | |
TaskId | registerTask (std::unique_ptr< Task > task) |
void | removeTask (TaskId taskId) |
TaskId | getTaskId (const std::string &taskName) const |
void | addDependency (TaskId predecessor, TaskId successor) |
bool | addDependency (const std::string &predecessors, TaskId successor) |
bool | addDependency (TaskId predecessor, const std::string &successors) |
void | addPendingDependency (const std::string &predecessors, TaskId successor) |
void | addPendingDependency (TaskId predecessor, const std::string &successors) |
void | startTasks () |
void | runTasksInThisThread () |
void | waitForTasks () |
Blocks until all tasks and dependencies are finished. | |
const std::vector< TimerData > & | getTimerData () |
Access the data from the last frame execution after processTaskQueue();. | |
void | flushTaskQueue () |
Erases all tasks. Will assert if tasks are unprocessed. | |
void | printTaskGraph (std::ostream &output) const |
Prints the current task graph in dot format. | |
This class allows tasks to be registered and then executed in parallel on separate threads.
It maintains an internal pool of threads. When instructed, it dispatches the tasks to the pooled threads. Task are allowed to have dependencies. A task will be executed only when all its dependencies are satisfied, i.e. all dependant tasks are finished. Note that most functions are not thread safe and must not be called when the task queue is running. Typical usage:
Definition at line 47 of file TaskQueue.hpp.
using Ra::Core::TaskQueue::TaskId = Utils::Index |
Identifier for a task in the task queue.
Definition at line 51 of file TaskQueue.hpp.
|
explicit |
Constructor. Initializes the thread worker pools with numThreads threads. if numThreads == 0, its a runTasksInThisThread only task queue
Definition at line 14 of file TaskQueue.cpp.
Ra::Core::TaskQueue::~TaskQueue | ( | ) |
Destructor. Waits for all the threads and safely deletes them.
Definition at line 22 of file TaskQueue.cpp.
bool Ra::Core::TaskQueue::addDependency | ( | const std::string & | predecessors, |
TaskQueue::TaskId | successor ) |
Add dependency between a task and all task with a given name. Will return false if no dependency has been added.
Definition at line 94 of file TaskQueue.cpp.
bool Ra::Core::TaskQueue::addDependency | ( | TaskQueue::TaskId | predecessor, |
const std::string & | successors ) |
Definition at line 106 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::addDependency | ( | TaskQueue::TaskId | predecessor, |
TaskQueue::TaskId | successor ) |
Add dependency between two tasks. The successor task will be executed only when all its predecessor completed.
Definition at line 77 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::addPendingDependency | ( | const std::string & | predecessors, |
TaskQueue::TaskId | successor ) |
Add a dependency between a task an all tasks with a given name, even if the task is not present yet, the name being resolved when task start.
Definition at line 117 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::addPendingDependency | ( | TaskId | predecessor, |
const std::string & | successors ) |
Definition at line 123 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::flushTaskQueue | ( | ) |
Erases all tasks. Will assert if tasks are unprocessed.
Definition at line 269 of file TaskQueue.cpp.
TaskQueue::TaskId Ra::Core::TaskQueue::getTaskId | ( | const std::string & | taskName | ) | const |
Definition at line 67 of file TaskQueue.cpp.
const std::vector< TaskQueue::TimerData > & Ra::Core::TaskQueue::getTimerData | ( | ) |
Access the data from the last frame execution after processTaskQueue();.
Definition at line 265 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::printTaskGraph | ( | std::ostream & | output | ) | const |
Prints the current task graph in dot format.
Definition at line 338 of file TaskQueue.cpp.
TaskQueue::TaskId Ra::Core::TaskQueue::registerTask | ( | std::unique_ptr< Task > | task | ) |
Registers a task to be executed. Task must have been created with new and be initialized with its parameter. The task queue assumes ownership of the task.
Definition at line 33 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::removeTask | ( | TaskId | taskId | ) |
remove a task, in fact simply replace the task by a dummy empty one. hence do not affect dependencies don't affect other task id's
Definition at line 50 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::runTasksInThisThread | ( | ) |
Launches the execution of all task in the thread of the caller. Return when all tasks are done. Usefull for instance for opengl related tasks that must run in the context thread. Once tasks are all processed, this method call flushTasksQueue.
Definition at line 214 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::startTasks | ( | ) |
Launches the execution of all the tasks in the task queue. No more tasks should be added at this point.
Definition at line 185 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::waitForTasks | ( | ) |
Blocks until all tasks and dependencies are finished.
Definition at line 259 of file TaskQueue.cpp.