Radium Engine  1.5.0
Ra::Core::TaskQueue Class Reference

#include <Core/Tasks/TaskQueue.hpp>

+ Collaboration diagram for Ra::Core::TaskQueue:

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TaskQueue()

Ra::Core::TaskQueue::TaskQueue ( uint  numThreads)
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.

Member Function Documentation

◆ addDependency() [1/2]

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.

+ Here is the call graph for this function:

◆ addDependency() [2/2]

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.

◆ addPendingDependency()

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.

◆ registerTask()

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.

◆ removeTask()

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.

◆ runTasksInThisThread()

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.

+ Here is the call graph for this function:

◆ startTasks()

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.


The documentation for this class was generated from the following files: