Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::mt::ThreadPool Class Referencefinal

Public Member Functions

void make_main_thread ()
 Make the calling thread the effective main thread from the thread pool perspective.
 
GAIA_NODISCARD uint32_t workers () const
 Returns the number of worker threads.
 
void set_max_workers (uint32_t count, uint32_t countHighPrio)
 Set the maximum number of workers for this system.
 
void set_workers_high_prio_inter (uint32_t &workerIdx, uint32_t count)
 Updates the number of worker threads participating at high priority workloads.
 
void set_workers_low_prio_inter (uint32_t &workerIdx, uint32_t count)
 Updates the number of worker threads participating at low priority workloads.
 
void set_workers_high_prio (uint32_t count)
 Updates the number of worker threads participating at high priority workloads.
 
void set_workers_low_prio (uint32_t count)
 Updates the number of worker threads participating at low priority workloads.
 
void dep (JobHandle jobFirst, JobHandle jobSecond)
 Makes jobSecond depend on jobFirst. This means jobSecond will not run until jobFirst finishes.
 
void dep (std::span< JobHandle > jobsFirst, JobHandle jobSecond)
 Makes jobSecond depend on the jobs listed in jobsFirst. This means jobSecond will not run until all jobs from jobsFirst finish.
 
void dep_refresh (JobHandle jobFirst, JobHandle jobSecond)
 Makes jobSecond depend on jobFirst. This means jobSecond will not run until jobFirst finishes.
 
void dep_refresh (std::span< JobHandle > jobsFirst, JobHandle jobSecond)
 Makes jobSecond depend on the jobs listed in jobsFirst. This means jobSecond will not run until all jobs from jobsFirst finish.
 
template<typename TJob >
JobHandle add (TJob &&job)
 Creates a threadpool job from job.
 
void del (JobHandle jobHandle)
 Deletes a job handle jobHandle from the threadpool.
 
void submit (std::span< JobHandle > jobHandles)
 Pushes jobHandles into the internal queue so worker threads can pick them up and execute them. If there are more jobs than the queue can handle it puts the calling thread to sleep until workers consume enough jobs.
 
void submit (JobHandle jobHandle)
 Pushes jobHandle into the internal queue so worker threads can pick it up and execute it. If there are more jobs than the queue can handle it puts the calling thread to sleep until workers consume enough jobs.
 
void reset_state (std::span< JobHandle > jobHandles)
 
void reset_state (JobHandle jobHandle)
 
JobHandle sched (Job &job)
 Schedules a job to run on a worker thread.
 
JobHandle sched (Job &job, JobHandle dependsOn)
 Schedules a job to run on a worker thread.
 
JobHandle sched_par (JobParallel &job, uint32_t itemsToProcess, uint32_t groupSize)
 Schedules a job to run on worker threads in parallel.
 
void wait (JobHandle jobHandle)
 Wait until a job associated with the jobHandle finishes executing. Cleans up any job allocations and dependencies associated with jobHandle The calling thread participate in job processing until jobHandle is done.
 
void update ()
 Uses the main thread to help with jobs processing.
 

Static Public Member Functions

static ThreadPoolget ()
 
static GAIA_NODISCARD uint32_t hw_thread_cnt ()
 Returns the number of HW threads available on the system. 1 is minimum.
 
static GAIA_NODISCARD uint32_t hw_efficiency_cores_cnt ()
 Returns the number of efficiency cores of the system.
 

Friends

class JobManager
 

Member Function Documentation

◆ add()

template<typename TJob >
JobHandle gaia::mt::ThreadPool::add ( TJob &&  job)
inline

Creates a threadpool job from job.

Warning
Must be used from the main thread.
Can't be called while there are any jobs being executed.
Returns
Job handle of the scheduled job.

◆ del()

void gaia::mt::ThreadPool::del ( JobHandle  jobHandle)
inline

Deletes a job handle jobHandle from the threadpool.

Warning
Job handle must not be used by any worker thread and can not be used by any active job handles as a dependency.

◆ dep() [1/2]

void gaia::mt::ThreadPool::dep ( JobHandle  jobFirst,
JobHandle  jobSecond 
)
inline

Makes jobSecond depend on jobFirst. This means jobSecond will not run until jobFirst finishes.

Parameters
jobFirstThe job that must complete first.
jobSecondThe job that will run after jobFirst.
Warning
This must be called before any of the listed jobs are scheduled.

◆ dep() [2/2]

void gaia::mt::ThreadPool::dep ( std::span< JobHandle jobsFirst,
JobHandle  jobSecond 
)
inline

Makes jobSecond depend on the jobs listed in jobsFirst. This means jobSecond will not run until all jobs from jobsFirst finish.

Parameters
jobsFirstJobs that must complete first.
jobSecondThe job that will run after jobsFirst.
Warning
This must must to be called before any of the listed jobs are scheduled.

◆ dep_refresh() [1/2]

void gaia::mt::ThreadPool::dep_refresh ( JobHandle  jobFirst,
JobHandle  jobSecond 
)
inline

Makes jobSecond depend on jobFirst. This means jobSecond will not run until jobFirst finishes.

Parameters
jobFirstThe job that must complete first.
jobSecondThe job that will run after jobFirst.
Note
Unlike dep() this function needs to be called when job handles are reused.
Warning
This must be called before any of the listed jobs are scheduled.
This must be called from the main thread.

◆ dep_refresh() [2/2]

void gaia::mt::ThreadPool::dep_refresh ( std::span< JobHandle jobsFirst,
JobHandle  jobSecond 
)
inline

Makes jobSecond depend on the jobs listed in jobsFirst. This means jobSecond will not run until all jobs from jobsFirst finish.

Parameters
jobsFirstJobs that must complete first.
jobSecondThe job that will run after jobsFirst.
Note
Unlike dep() this function needs to be called when job handles are reused.
Warning
This must be called before any of the listed jobs are scheduled.
This must be called from the main thread.

◆ hw_efficiency_cores_cnt()

static GAIA_NODISCARD uint32_t gaia::mt::ThreadPool::hw_efficiency_cores_cnt ( )
inlinestatic

Returns the number of efficiency cores of the system.

Returns
The number of efficiency cores. 0 if failed, or if there are no such cores.

◆ hw_thread_cnt()

static GAIA_NODISCARD uint32_t gaia::mt::ThreadPool::hw_thread_cnt ( )
inlinestatic

Returns the number of HW threads available on the system. 1 is minimum.

Returns
The number of hardware threads or 1 if failed.

◆ sched() [1/2]

JobHandle gaia::mt::ThreadPool::sched ( Job job)
inline

Schedules a job to run on a worker thread.

Parameters
jobJob descriptor
Warning
Must be used from the main thread.
Dependencies can't be modified for this job.
Returns
Job handle of the scheduled job.

◆ sched() [2/2]

JobHandle gaia::mt::ThreadPool::sched ( Job job,
JobHandle  dependsOn 
)
inline

Schedules a job to run on a worker thread.

Parameters
jobJob descriptor
dependsOnJob we depend on
Warning
Must be used from the main thread.
Dependencies can't be modified for this job.
Returns
Job handle of the scheduled job.

◆ sched_par()

JobHandle gaia::mt::ThreadPool::sched_par ( JobParallel job,
uint32_t  itemsToProcess,
uint32_t  groupSize 
)
inline

Schedules a job to run on worker threads in parallel.

Parameters
jobJob descriptor
itemsToProcessTotal number of work items
groupSizeGroup size per created job. If zero the threadpool decides the group size.
Warning
Must be used from the main thread.
Dependencies can't be modified for this job.
Returns
Job handle of the scheduled batch of jobs.

◆ set_max_workers()

void gaia::mt::ThreadPool::set_max_workers ( uint32_t  count,
uint32_t  countHighPrio 
)
inline

Set the maximum number of workers for this system.

Parameters
countRequested number of worker threads to create.
countHighPrioHighPrio Number of high-priority workers to create. Calculated as Max(count, countHighPrio).
Warning
All jobs are finished first before threads are recreated.

◆ set_workers_high_prio()

void gaia::mt::ThreadPool::set_workers_high_prio ( uint32_t  count)
inline

Updates the number of worker threads participating at high priority workloads.

Warning
All jobs are finished first before threads are recreated.

◆ set_workers_high_prio_inter()

void gaia::mt::ThreadPool::set_workers_high_prio_inter ( uint32_t &  workerIdx,
uint32_t  count 
)
inline

Updates the number of worker threads participating at high priority workloads.

Parameters
[out]workerIdxNumber of high priority workers.
countRequested number of high priority workers.
Warning
All jobs are finished first before threads are recreated.

◆ set_workers_low_prio()

void gaia::mt::ThreadPool::set_workers_low_prio ( uint32_t  count)
inline

Updates the number of worker threads participating at low priority workloads.

Warning
All jobs are finished first before threads are recreated.

◆ set_workers_low_prio_inter()

void gaia::mt::ThreadPool::set_workers_low_prio_inter ( uint32_t &  workerIdx,
uint32_t  count 
)
inline

Updates the number of worker threads participating at low priority workloads.

Parameters
[out]workerIdxNumber of low priority workers.
countRequested number of low priority workers.
Warning
All jobs are finished first before threads are recreated.

◆ submit() [1/2]

void gaia::mt::ThreadPool::submit ( JobHandle  jobHandle)
inline

Pushes jobHandle into the internal queue so worker threads can pick it up and execute it. If there are more jobs than the queue can handle it puts the calling thread to sleep until workers consume enough jobs.

Warning
Once submitted, dependencies can't be modified for this job.

◆ submit() [2/2]

void gaia::mt::ThreadPool::submit ( std::span< JobHandle jobHandles)
inline

Pushes jobHandles into the internal queue so worker threads can pick them up and execute them. If there are more jobs than the queue can handle it puts the calling thread to sleep until workers consume enough jobs.

Warning
Once submitted, dependencies can't be modified for this job.

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