Radium Engine
1.5.0
|
#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.
Definition at line 31 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.
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 90 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 73 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 113 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 30 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 47 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 203 of file TaskQueue.cpp.
void Ra::Core::TaskQueue::startTasks | ( | ) |
Launches the execution of all the threads in the task queue. No more tasks should be added at this point.
Definition at line 179 of file TaskQueue.cpp.