Drag[en]gine Game Engine
1.21
|
Parallel processing task. More...
#include <deParallelTask.h>
Public Member Functions | |
Management | |
deBaseModule * | GetOwner () const |
Module owning the task or NULL if global. More... | |
bool | GetMarkFinishedAfterRun () const |
Mark task finished after Run() method leaves. More... | |
void | SetMarkFinishedAfterRun (bool markFinishedAfterRun) |
Set if task is marked finished after Run() method leaves. More... | |
bool | GetEmptyRun () const |
Task has empty run implementation. More... | |
void | SetEmptyRun (bool emptyRun) |
Set if task has empty run implementation. More... | |
bool | GetLowPriority () const |
Task has lower priority than other tasks. More... | |
void | SetLowPriority (bool lowPriority) |
Set if task has lower priority than other tasks. More... | |
bool | IsCancelled () const |
Task has been cancelled. More... | |
void | Cancel () |
Cancel task. More... | |
bool | GetFinished () const |
Task is finished. More... | |
void | SetFinished () |
Set task finished. More... | |
int | GetDependsOnCount () const |
Number of tasks this task depends on. More... | |
deParallelTask * | GetDependsOnAt (int index) const |
Depend on task at index. More... | |
bool | DoesDependOn (deParallelTask *task) const |
Task depends on another task. More... | |
void | AddDependsOn (deParallelTask *task) |
Add task this task depends on. More... | |
void | RemoveDependsOn (deParallelTask *task) |
Remove task this task depends on. More... | |
void | RemoveAllDependsOn () |
Remove all tasks this task depends on. More... | |
decThreadSafeObjectOrderedSet & | GetDependedOnBy () |
List of tasks depending on this task. More... | |
const decThreadSafeObjectOrderedSet & | GetDependedOnBy () const |
void | RemoveFromAllDependedOnTasks () |
Remove from all tasks depending on this task. More... | |
bool | CanRun () const |
Task can run. More... | |
void | Reset () |
Reset task. More... | |
Subclass Responsibility | |
virtual void | Run ()=0 |
Parallel task implementation. More... | |
virtual void | Finished ()=0 |
Processing of task Run() finished. More... | |
virtual void | Cancelled () |
Parallel task implementation has been cancelled. More... | |
Debugging | |
virtual decString | GetDebugName () const |
Short task name for debugging. More... | |
virtual decString | GetDebugDetails () const |
Task details for debugging. More... | |
Public Member Functions inherited from deThreadSafeObject | |
int | GetRefCount () |
Reference count. More... | |
void | AddReference () |
Add reference increasing reference count by 1. More... | |
void | FreeReference () |
Decrease reference count by one and delete object if count reaches 0. More... | |
deThreadSafeObject () | |
Create object with reference count of 1. More... | |
Constructors and Destructors | |
deParallelTask (deBaseModule *owner) | |
Create task. More... | |
virtual | ~deParallelTask () |
Clean up task. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from deThreadSafeObject | |
virtual | ~deThreadSafeObject () |
Clean up object. More... | |
Parallel processing task.
Subclass to implement task to run. Tasks have to finished as quick as possible to allow for best throughput. Tasks can be assigned as dependency of other tasks. A task will not run unless all dependency tasks are marked finished. There are two kinds of parallel tasks differeing in when they are marked finished.
Purely asynchronous tasks chained with each other are marked finished after their Run() methods exist. This allows a chain of tasks to run one after the other without waiting for the application to do another frame loop. Their Finished() methods are called during the next time the a frame loop is started. Tasks of this kind do require only the calculated result of the previous task Run() method not Finished(). In general these kind of task chains have to complete during the same frame loop.
Partially asynchronous tasks chained with each other require their Finished() method to be called during the next frame loop for subsequent tasks to function properly. These tasks are mark finished after their Finished() method exists. Task chains of this kind can not run through fully in one frame loop. Although spreading across multiple frame loops they do not block parallel processing threads. they are optimal for complex tasks split into small chunks of work not required to be calculated in a single frame loop.
Use SetFinishAfterRun() to set the appropriate behavior.
deParallelTask::deParallelTask | ( | deBaseModule * | owner | ) |
Create task.
[in] | owner | Module owning the task or NULL if global. |
|
protectedvirtual |
Clean up task.
void deParallelTask::AddDependsOn | ( | deParallelTask * | task | ) |
Add task this task depends on.
deeInvalidParam | task is NULL. |
deeInvalidParam | task is this task. |
deeInvalidParam | task has been already added. |
void deParallelTask::Cancel | ( | ) |
Cancel task.
Call from the main thread to cancel a task. A cancelled task does not call Finished() or Run() if still pending.
|
virtual |
Parallel task implementation has been cancelled.
Called if Cancel() is called. This allows tasks marked as finished after run to trigger required actions as if Run() has been called.
The default implementation is empty.
bool deParallelTask::CanRun | ( | ) | const |
Task can run.
bool deParallelTask::DoesDependOn | ( | deParallelTask * | task | ) | const |
Task depends on another task.
|
pure virtual |
Processing of task Run() finished.
Called after the task has finished and has been collected by deParallelProcessing::Update(). This call runs synchronously in the main engine thread. You have to check using IsCancelled() if the task has been cancelled or finished successfully. Finished() will be called in all circumstances to allow proper cleaning up.
Implemented in deRLTaskWriteRig, deRLTaskWriteOcclusionMesh, deRLTaskWriteModel, deRLTaskWriteImage, deRLTaskWriteAnimation, deRLTaskReadVideo, deRLTaskReadSound, deRLTaskReadSkinInternal, deRLTaskReadSkin, deRLTaskReadRig, deRLTaskReadOcclusionMesh, deRLTaskReadModel, deRLTaskReadLanguagePack, deRLTaskReadImage, deRLTaskReadFontInternal2, deRLTaskReadFontInternal, deRLTaskReadFont, and deRLTaskReadAnimation.
|
virtual |
Task details for debugging.
Reimplemented in deResourceLoaderTask.
|
virtual |
Short task name for debugging.
Reimplemented in deRLTaskWriteRig, deRLTaskWriteOcclusionMesh, deRLTaskWriteModel, deRLTaskWriteImage, deRLTaskWriteAnimation, deRLTaskReadVideo, deRLTaskReadSound, deRLTaskReadSkinInternal, deRLTaskReadSkin, deRLTaskReadRig, deRLTaskReadOcclusionMesh, deRLTaskReadModel, deRLTaskReadLanguagePack, deRLTaskReadImage, deRLTaskReadFontInternal2, deRLTaskReadFontInternal, deRLTaskReadFont, deRLTaskReadAnimation, and deResourceLoaderTask.
|
inline |
List of tasks depending on this task.
Used by deParallelProcessing only.
|
inline |
deParallelTask* deParallelTask::GetDependsOnAt | ( | int | index | ) | const |
Depend on task at index.
int deParallelTask::GetDependsOnCount | ( | ) | const |
Number of tasks this task depends on.
|
inline |
Task has empty run implementation.
|
inline |
Task is finished.
|
inline |
Task has lower priority than other tasks.
|
inline |
Mark task finished after Run() method leaves.
Default value is true.
true | Task is marked finished after Run() method exits. |
false | Task is marked finished after Finished() method exits. |
|
inline |
Module owning the task or NULL if global.
|
inline |
Task has been cancelled.
void deParallelTask::RemoveAllDependsOn | ( | ) |
Remove all tasks this task depends on.
void deParallelTask::RemoveDependsOn | ( | deParallelTask * | task | ) |
Remove task this task depends on.
deeInvalidParam | task is NULL. |
deeInvalidParam | task is this task. |
deeInvalidParam | task has not been added. |
void deParallelTask::RemoveFromAllDependedOnTasks | ( | ) |
Remove from all tasks depending on this task.
Used by deParallelProcessing only.
void deParallelTask::Reset | ( | ) |
Reset task.
Used only by deParallelProcessing.
|
pure virtual |
Parallel task implementation.
Implemented in deRLTaskWriteRig, deRLTaskWriteOcclusionMesh, deRLTaskWriteModel, deRLTaskWriteImage, deRLTaskWriteAnimation, deRLTaskReadVideo, deRLTaskReadSound, deRLTaskReadSkinInternal, deRLTaskReadSkin, deRLTaskReadRig, deRLTaskReadOcclusionMesh, deRLTaskReadModel, deRLTaskReadLanguagePack, deRLTaskReadImage, deRLTaskReadFontInternal2, deRLTaskReadFontInternal, deRLTaskReadFont, and deRLTaskReadAnimation.
void deParallelTask::SetEmptyRun | ( | bool | emptyRun | ) |
Set if task has empty run implementation.
This is an optimization. If the run implementation is empty the task will be finished without running the empty run method using a free thread.
void deParallelTask::SetFinished | ( | ) |
Set task finished.
Call from Run() or Finished() to allow tasks dependeing on this task to start running.
void deParallelTask::SetLowPriority | ( | bool | lowPriority | ) |
Set if task has lower priority than other tasks.
void deParallelTask::SetMarkFinishedAfterRun | ( | bool | markFinishedAfterRun | ) |
Set if task is marked finished after Run() method leaves.
finishAfterRun | If true task is marked finished after Run() method exits. If false Task is marked finished after Finished() method exits. |