Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
JobSystemThreadPool Class Referencefinal

#include <JobSystemThreadPool.h>

Inheritance diagram for JobSystemThreadPool:
JobSystemWithBarrier JobSystem NonCopyable

Public Types

using InitExitFunction = function< void(int)>
 Functions to call when a thread is initialized or exits, must be set before calling Init()
 
- Public Types inherited from JobSystem
using JobFunction = function< void()>
 Main function of the job.
 

Public Member Functions

JPH_OVERRIDE_NEW_DELETE JobSystemThreadPool (uint inMaxJobs, uint inMaxBarriers, int inNumThreads=-1)
 
 JobSystemThreadPool ()=default
 
virtual ~JobSystemThreadPool () override
 
void SetThreadInitFunction (const InitExitFunction &inInitFunction)
 
void SetThreadExitFunction (const InitExitFunction &inExitFunction)
 
void Init (uint inMaxJobs, uint inMaxBarriers, int inNumThreads=-1)
 
virtual int GetMaxConcurrency () const override
 Get maximum number of concurrently executing jobs.
 
virtual JobHandle CreateJob (const char *inName, ColorArg inColor, const JobFunction &inJobFunction, uint32 inNumDependencies=0) override
 
void SetNumThreads (int inNumThreads)
 Change the max concurrency after initialization.
 
- Public Member Functions inherited from JobSystemWithBarrier
JPH_OVERRIDE_NEW_DELETE JobSystemWithBarrier (uint inMaxBarriers)
 
 JobSystemWithBarrier ()=default
 
virtual ~JobSystemWithBarrier () override
 
void Init (uint inMaxBarriers)
 
virtual BarrierCreateBarrier () override
 Create a new barrier, used to wait on jobs.
 
virtual void DestroyBarrier (Barrier *inBarrier) override
 Destroy a barrier when it is no longer used. The barrier should be empty at this point.
 
virtual void WaitForJobs (Barrier *inBarrier) override
 Wait for a set of jobs to be finished, note that only 1 thread can be waiting on a barrier at a time.
 
- Public Member Functions inherited from JobSystem
virtual ~JobSystem ()=default
 Destructor.
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Protected Member Functions

virtual void QueueJob (Job *inJob) override
 Adds a job to the job queue.
 
virtual void QueueJobs (Job **inJobs, uint inNumJobs) override
 Adds a number of jobs at once to the job queue.
 
virtual void FreeJob (Job *inJob) override
 Frees a job.
 

Detailed Description

Implementation of a JobSystem using a thread pool

Note that this is considered an example implementation. It is expected that when you integrate the physics engine into your own project that you'll provide your own implementation of the JobSystem built on top of whatever job system your project uses.

Member Typedef Documentation

◆ InitExitFunction

using JobSystemThreadPool::InitExitFunction = function<void(int)>

Functions to call when a thread is initialized or exits, must be set before calling Init()

Constructor & Destructor Documentation

◆ JobSystemThreadPool() [1/2]

JobSystemThreadPool::JobSystemThreadPool ( uint  inMaxJobs,
uint  inMaxBarriers,
int  inNumThreads = -1 
)

Creates a thread pool.

See also
JobSystemThreadPool::Init

◆ JobSystemThreadPool() [2/2]

JobSystemThreadPool::JobSystemThreadPool ( )
default

◆ ~JobSystemThreadPool()

JobSystemThreadPool::~JobSystemThreadPool ( )
overridevirtual

Member Function Documentation

◆ CreateJob()

JobHandle JobSystemThreadPool::CreateJob ( const char *  inName,
ColorArg  inColor,
const JobFunction inJobFunction,
uint32  inNumDependencies = 0 
)
overridevirtual

Create a new job, the job is started immediately if inNumDependencies == 0 otherwise it starts when RemoveDependency causes the dependency counter to reach 0.

Implements JobSystem.

◆ FreeJob()

void JobSystemThreadPool::FreeJob ( Job inJob)
overrideprotectedvirtual

Frees a job.

Implements JobSystem.

◆ GetMaxConcurrency()

virtual int JobSystemThreadPool::GetMaxConcurrency ( ) const
inlineoverridevirtual

Get maximum number of concurrently executing jobs.

Implements JobSystem.

◆ Init()

JPH_NAMESPACE_BEGIN void JobSystemThreadPool::Init ( uint  inMaxJobs,
uint  inMaxBarriers,
int  inNumThreads = -1 
)

Initialize the thread pool

Parameters
inMaxJobsMax number of jobs that can be allocated at any time
inMaxBarriersMax number of barriers that can be allocated at any time
inNumThreadsNumber of threads to start (the number of concurrent jobs is 1 more because the main thread will also run jobs while waiting for a barrier to complete). Use -1 to auto detect the amount of CPU's.

◆ QueueJob()

void JobSystemThreadPool::QueueJob ( Job inJob)
overrideprotectedvirtual

Adds a job to the job queue.

Implements JobSystem.

◆ QueueJobs()

void JobSystemThreadPool::QueueJobs ( Job **  inJobs,
uint  inNumJobs 
)
overrideprotectedvirtual

Adds a number of jobs at once to the job queue.

Implements JobSystem.

◆ SetNumThreads()

void JobSystemThreadPool::SetNumThreads ( int  inNumThreads)
inline

Change the max concurrency after initialization.

◆ SetThreadExitFunction()

void JobSystemThreadPool::SetThreadExitFunction ( const InitExitFunction inExitFunction)
inline

◆ SetThreadInitFunction()

void JobSystemThreadPool::SetThreadInitFunction ( const InitExitFunction inInitFunction)
inline

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