Drag[en]gine Game Engine  1.21
deParallelTask Class Referenceabstract

Parallel processing task. More...

#include <deParallelTask.h>

Inheritance diagram for deParallelTask:
deThreadSafeObject deResourceLoaderTask deRLTaskReadAnimation deRLTaskReadFont deRLTaskReadFontInternal deRLTaskReadFontInternal2 deRLTaskReadImage deRLTaskReadLanguagePack deRLTaskReadModel deRLTaskReadOcclusionMesh deRLTaskReadRig deRLTaskReadSkin deRLTaskReadSkinInternal deRLTaskReadSound deRLTaskReadVideo deRLTaskWriteAnimation deRLTaskWriteImage deRLTaskWriteModel deRLTaskWriteOcclusionMesh deRLTaskWriteRig

Public Member Functions

Management
deBaseModuleGetOwner () 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...
 
deParallelTaskGetDependsOnAt (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...
 
decThreadSafeObjectOrderedSetGetDependedOnBy ()
 List of tasks depending on this task. More...
 
const decThreadSafeObjectOrderedSetGetDependedOnBy () 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...
 

Detailed Description

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.

Note
If the task is cancelled before Run() is called the task is marked finished at the time Cancel() is called.

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.

Note
If the task is cancelled before Run() is called the task is marked finished after Finished() is called.

Use SetFinishAfterRun() to set the appropriate behavior.

Constructor & Destructor Documentation

◆ deParallelTask()

deParallelTask::deParallelTask ( deBaseModule owner)

Create task.

Parameters
[in]ownerModule owning the task or NULL if global.

◆ ~deParallelTask()

virtual deParallelTask::~deParallelTask ( )
protectedvirtual

Clean up task.

Member Function Documentation

◆ AddDependsOn()

void deParallelTask::AddDependsOn ( deParallelTask task)

Add task this task depends on.

Exceptions
deeInvalidParamtask is NULL.
deeInvalidParamtask is this task.
deeInvalidParamtask has been already added.

◆ Cancel()

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.

◆ Cancelled()

virtual void deParallelTask::Cancelled ( )
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.

Warning
Can be called while Run() is running. Implementations have to cope with this.
Do not manipulate the reference count or depends-on of the tasks or any task depending on it.
Due to implementation details it is possible (although unlikely) this function is called more than once. Implementations have to cope with this.

◆ CanRun()

bool deParallelTask::CanRun ( ) const

Task can run.

Returns
true if task does not depend on other tasks or all other tasks finished.

◆ DoesDependOn()

bool deParallelTask::DoesDependOn ( deParallelTask task) const

Task depends on another task.

◆ Finished()

virtual void deParallelTask::Finished ( )
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.

Note
It is allowed to start new tasks from inside Finished().
When called the 'depends on' and 'depended on by' list will be empty.
Warning
Do not re-add this tasks from inside Finished().
Do as little work as possible here to not stall too much.

Implemented in deRLTaskWriteRig, deRLTaskWriteOcclusionMesh, deRLTaskWriteModel, deRLTaskWriteImage, deRLTaskWriteAnimation, deRLTaskReadVideo, deRLTaskReadSound, deRLTaskReadSkinInternal, deRLTaskReadSkin, deRLTaskReadRig, deRLTaskReadOcclusionMesh, deRLTaskReadModel, deRLTaskReadLanguagePack, deRLTaskReadImage, deRLTaskReadFontInternal2, deRLTaskReadFontInternal, deRLTaskReadFont, and deRLTaskReadAnimation.

◆ GetDebugDetails()

virtual decString deParallelTask::GetDebugDetails ( ) const
virtual

Task details for debugging.

Reimplemented in deResourceLoaderTask.

◆ GetDebugName()

◆ GetDependedOnBy() [1/2]

decThreadSafeObjectOrderedSet& deParallelTask::GetDependedOnBy ( )
inline

List of tasks depending on this task.

Used by deParallelProcessing only.

◆ GetDependedOnBy() [2/2]

const decThreadSafeObjectOrderedSet& deParallelTask::GetDependedOnBy ( ) const
inline

◆ GetDependsOnAt()

deParallelTask* deParallelTask::GetDependsOnAt ( int  index) const

Depend on task at index.

◆ GetDependsOnCount()

int deParallelTask::GetDependsOnCount ( ) const

Number of tasks this task depends on.

◆ GetEmptyRun()

bool deParallelTask::GetEmptyRun ( ) const
inline

Task has empty run implementation.

◆ GetFinished()

bool deParallelTask::GetFinished ( ) const
inline

Task is finished.

◆ GetLowPriority()

bool deParallelTask::GetLowPriority ( ) const
inline

Task has lower priority than other tasks.

◆ GetMarkFinishedAfterRun()

bool deParallelTask::GetMarkFinishedAfterRun ( ) const
inline

Mark task finished after Run() method leaves.

Default value is true.

Return values
trueTask is marked finished after Run() method exits.
falseTask is marked finished after Finished() method exits.

◆ GetOwner()

deBaseModule* deParallelTask::GetOwner ( ) const
inline

Module owning the task or NULL if global.

◆ IsCancelled()

bool deParallelTask::IsCancelled ( ) const
inline

Task has been cancelled.

◆ RemoveAllDependsOn()

void deParallelTask::RemoveAllDependsOn ( )

Remove all tasks this task depends on.

◆ RemoveDependsOn()

void deParallelTask::RemoveDependsOn ( deParallelTask task)

Remove task this task depends on.

Exceptions
deeInvalidParamtask is NULL.
deeInvalidParamtask is this task.
deeInvalidParamtask has not been added.

◆ RemoveFromAllDependedOnTasks()

void deParallelTask::RemoveFromAllDependedOnTasks ( )

Remove from all tasks depending on this task.

Used by deParallelProcessing only.

◆ Reset()

void deParallelTask::Reset ( )

Reset task.

Used only by deParallelProcessing.

◆ Run()

◆ SetEmptyRun()

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.

◆ SetFinished()

void deParallelTask::SetFinished ( )

Set task finished.

Call from Run() or Finished() to allow tasks dependeing on this task to start running.

◆ SetLowPriority()

void deParallelTask::SetLowPriority ( bool  lowPriority)

Set if task has lower priority than other tasks.

◆ SetMarkFinishedAfterRun()

void deParallelTask::SetMarkFinishedAfterRun ( bool  markFinishedAfterRun)

Set if task is marked finished after Run() method leaves.

Parameters
finishAfterRunIf true task is marked finished after Run() method exits. If false Task is marked finished after Finished() method exits.

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