Games Task Scheduler (GTS)
A multi-processor scheduling framework for games engines
gts::Task Class Referenceabstract

A Task payload that embeds TFunc and TArgs into the Task's data. It makes it easy to construct a Task from a lambda or a function plus arguments similar to std::thread. More...

#include <Task.h>

Inherited by gts::CStyleTask, gts::EmptyTask, gts::LambdaTaskWrapper< TFunc, TArgs >, gts::MicroScheduler_Task, gts_examples::BadParallelFor::ForTask< TFunc >, gts_examples::BasicTask, gts_examples::GridSumTask, gts_examples::ParallelFibContinuationTask, gts_examples::ParallelFibContinuationTask3, gts_examples::ParallelFibContinuationTask4, gts_examples::ParallelFibTask1, gts_examples::ParallelFibTask2, gts_examples::ParallelFibTask3, and gts_examples::ParallelFibTask4.

Public Member Functions

virtual Taskexecute (TaskContext const &ctx)=0
 
GTS_INLINE void addChildTaskWithoutRef (Task *pChild)
 
GTS_INLINE void addChildTaskWithRef (Task *pChild, gts::memory_order order=gts::memory_order::seq_cst)
 
GTS_INLINE void setContinuationTask (Task *pContinuation)
 
GTS_INLINE void recycle ()
 
void waitForAll ()
 
void spawnAndWaitForAll (Task *pChild)
 
GTS_INLINE void setAffinity (uint32_t workerIdx)
 
GTS_INLINE int32_t addRef (int32_t count=1, gts::memory_order order=gts::memory_order::seq_cst)
 
GTS_INLINE int32_t removeRef (int32_t count=1, gts::memory_order order=gts::memory_order::seq_cst)
 
GTS_INLINE void setRef (int32_t count, gts::memory_order order=gts::memory_order::seq_cst)
 
GTS_INLINE void setName (const char *name)
 
GTS_INLINE int32_t refCount (gts::memory_order order=gts::memory_order::acquire) const
 
GTS_INLINE uint32_t getAffinity () const
 
GTS_INLINE bool isStolen () const
 
GTS_INLINE Taskparent ()
 
GTS_INLINE const char * name () const
 

Friends

class MicroScheduler
 
class LocalScheduler
 
class Worker
 

Detailed Description

A Task payload that embeds TFunc and TArgs into the Task's data. It makes it easy to construct a Task from a lambda or a function plus arguments similar to std::thread.

Derivative of TBB Task. https://github.com/intel/tbb

Member Function Documentation

◆ addChildTaskWithoutRef()

void Task::addChildTaskWithoutRef ( Task pChild)

Adds pChild as a child of this task. It DOES NOT increment this task's ref count so the caller must have manually increment the reference count before calling this function. Failing to do so is undefined behavior. pChild cannot already have a parent.

◆ addChildTaskWithRef()

void Task::addChildTaskWithRef ( Task pChild,
gts::memory_order  order = gts::memory_order::seq_cst 
)

Adds pChild as a child of this task AND increments this task's ref count. pChild cannot already have a parent.

◆ addRef()

int32_t Task::addRef ( int32_t  count = 1,
gts::memory_order  order = gts::memory_order::seq_cst 
)

Adds a reference to the task.

◆ getAffinity()

uint32_t Task::getAffinity ( ) const
Returns
The current Worker affinity.

◆ isStolen()

bool Task::isStolen ( ) const
Returns
True if stolen.

◆ name()

const char * Task::name ( ) const
Returns
The name of the task.

◆ parent()

Task * Task::parent ( )
Returns
This task's parent. nullptr is no parent is set.

◆ recycle()

void Task::recycle ( )

Marks the task to be reused after it has finished executing. Makes the Task look like it was just allocated. If the task is not added into a task graph with addChild* or setContinuation or returned as a bypass Task, it will be spawned.

◆ refCount()

int32_t Task::refCount ( gts::memory_order  order = gts::memory_order::acquire) const
Returns
The current reference count.

◆ removeRef()

int32_t Task::removeRef ( int32_t  count = 1,
gts::memory_order  order = gts::memory_order::seq_cst 
)

Removes a reference from the task.

◆ setAffinity()

void Task::setAffinity ( uint32_t  workerIdx)

Force the task to run on a specific Worker thread.

◆ setContinuationTask()

void Task::setContinuationTask ( Task pContinuation)

Sets pContinuation as a continuation of this task. pContinuation cannot already have a parent.

◆ setName()

void Task::setName ( const char *  name)

Sets the name of the task.

◆ setRef()

void Task::setRef ( int32_t  count,
gts::memory_order  order = gts::memory_order::seq_cst 
)

Sets a reference count.

◆ spawnAndWaitForAll()

void gts::Task::spawnAndWaitForAll ( Task pChild)

Executes pChild immediately and then waits for all this Task's children to complete before continuing. While waiting, this task will execute other available work.

Remarks
Requires and extra reference be added for the wait. The wait is considered complete when this task's reference count == 2. The reference count will be set to 1 once the wait completes.

◆ waitForAll()

void gts::Task::waitForAll ( )

Waits for all this Task's children to complete before continuing. While waiting, this task will execute other available work.

Remarks
Requires and extra reference be added for the wait. The wait is considered complete when this task's reference count == 2. The reference count will be set to 1 once the wait completes.