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

A collection of running Worker threads that a MicroScheduler can be run on. More...

#include <WorkerPool.h>

Public Member Functions

 WorkerPool ()
 
 ~WorkerPool ()
 
bool initialize (uint32_t threadCount=0)
 
bool initialize (WorkerPoolDesc &desc)
 
bool shutdown ()
 
GTS_INLINE bool isRunning () const
 
GTS_INLINE uint32_t workerCount () const
 
OwnedId thisWorkerId () const
 
GTS_INLINE SubIdType poolId () const
 
void enumerateWorkerIds (Vector< OwnedId > &out) const
 
void enumerateWorkerTids (Vector< ThreadId > &out) const
 
MicroSchedulercurrentMicroScheduler () const
 

Static Public Member Functions

static void resetIdGenerator ()
 Resets the ID generator to 0. This is not safe if there are any living MicroSchedulers.
 

Friends

class Worker
 
class LocalScheduler
 
class MicroScheduler
 

Detailed Description

A collection of running Worker threads that a MicroScheduler can be run on.

Remarks
Must be initialized before use.

Constructor & Destructor Documentation

◆ WorkerPool()

gts::WorkerPool::WorkerPool ( )

Constructs a WorkerPool in an uninitialized state. The user must call WorkerPool::initialize to initialize the scheduler before use, otherwise calls to this WorkerPool are undefined.

◆ ~WorkerPool()

gts::WorkerPool::~WorkerPool ( )

Implicitly calls shutdown.

Member Function Documentation

◆ currentMicroScheduler()

MicroScheduler* gts::WorkerPool::currentMicroScheduler ( ) const
Returns
The current MicroScheduler running on this Worker thread.
Remarks
The return MicroScheduler pointer is not thread safe.

◆ enumerateWorkerIds()

void gts::WorkerPool::enumerateWorkerIds ( Vector< OwnedId > &  out) const
Returns
A vector of all Worker IDs in the pool.

◆ enumerateWorkerTids()

void gts::WorkerPool::enumerateWorkerTids ( Vector< ThreadId > &  out) const
Returns
A vector of all Worker OS Thread IDs in the pool, indexed by local ID.

◆ initialize() [1/2]

bool gts::WorkerPool::initialize ( uint32_t  threadCount = 0)

Simple thread count initializer. If threadCount is zero, initializes with hardware thread count.

◆ initialize() [2/2]

bool gts::WorkerPool::initialize ( WorkerPoolDesc desc)

Explicit initializer.

◆ isRunning()

GTS_INLINE bool gts::WorkerPool::isRunning ( ) const
inline
Returns
True if the scheduler is running, false otherwise.

◆ poolId()

GTS_INLINE SubIdType gts::WorkerPool::poolId ( ) const
inline
Returns
This WorkerPool's ID.

◆ shutdown()

bool gts::WorkerPool::shutdown ( )

Stops and destroys all workers.

◆ thisWorkerId()

OwnedId gts::WorkerPool::thisWorkerId ( ) const
Returns
The calling Worker thread's index.

◆ workerCount()

GTS_INLINE uint32_t gts::WorkerPool::workerCount ( ) const
inline
Returns
The number of worker threads in the scheduler.