Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
JobSystemSingleThreaded.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2023 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
14{
15public:
17
20 explicit JobSystemSingleThreaded(uint inMaxJobs) { Init(inMaxJobs); }
21
24 void Init(uint inMaxJobs);
25
26 // See JobSystem
27 virtual int GetMaxConcurrency() const override { return 1; }
28 virtual JobHandle CreateJob(const char *inName, ColorArg inColor, const JobFunction &inJobFunction, uint32 inNumDependencies = 0) override;
29 virtual Barrier * CreateBarrier() override;
30 virtual void DestroyBarrier(Barrier *inBarrier) override;
31 virtual void WaitForJobs(Barrier *inBarrier) override;
32
33protected:
34 // Dummy implementation of Barrier, all jobs are executed immediately
35 class BarrierImpl : public Barrier
36 {
37 public:
39
40 // See Barrier
41 virtual void AddJob(const JobHandle &inJob) override { /* We don't need to track jobs */ }
42 virtual void AddJobs(const JobHandle *inHandles, uint inNumHandles) override { /* We don't need to track jobs */ }
43
44 protected:
46 virtual void OnJobFinished(Job *inJob) override { /* We don't need to track jobs */ }
47 };
48
49 // See JobSystem
50 virtual void QueueJob(Job *inJob) override;
51 virtual void QueueJobs(Job **inJobs, uint inNumJobs) override;
52 virtual void FreeJob(Job *inJob) override;
53
56
60};
61
#define JPH_EXPORT
Definition Core.h:236
unsigned int uint
Definition Core.h:446
#define JPH_NAMESPACE_END
Definition Core.h:379
std::uint32_t uint32
Definition Core.h:449
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:31
Class that holds an RGBA color with 8-bits per component.
Definition Color.h:16
A job barrier keeps track of a number of jobs and allows waiting until they are all completed.
Definition JobSystem.h:123
Definition JobSystem.h:80
A class that contains information for a single unit of work.
Definition JobSystem.h:171
Definition JobSystem.h:70
virtual JobHandle CreateJob(const char *inName, ColorArg inColor, const JobFunction &inJobFunction, uint32 inNumDependencies=0)=0
virtual Barrier * CreateBarrier()=0
Create a new barrier, used to wait on jobs.
virtual void WaitForJobs(Barrier *inBarrier)=0
Wait for a set of jobs to be finished, note that only 1 thread can be waiting on a barrier at a time.
virtual void DestroyBarrier(Barrier *inBarrier)=0
Destroy a barrier when it is no longer used. The barrier should be empty at this point.
virtual void QueueJobs(Job **inJobs, uint inNumJobs)=0
Adds a number of jobs at once to the job queue.
virtual void FreeJob(Job *inJob)=0
Frees a job.
virtual void QueueJob(Job *inJob)=0
Adds a job to the job queue.
Definition JobSystemSingleThreaded.h:36
virtual void AddJobs(const JobHandle *inHandles, uint inNumHandles) override
Definition JobSystemSingleThreaded.h:42
virtual JPH_OVERRIDE_NEW_DELETE void AddJob(const JobHandle &inJob) override
Definition JobSystemSingleThreaded.h:41
virtual void OnJobFinished(Job *inJob) override
Called by a Job to mark that it is finished.
Definition JobSystemSingleThreaded.h:46
Implementation of a JobSystem without threads, runs jobs as soon as they are added.
Definition JobSystemSingleThreaded.h:14
BarrierImpl mDummyBarrier
Shared barrier since the barrier implementation does nothing.
Definition JobSystemSingleThreaded.h:55
AvailableJobs mJobs
Definition JobSystemSingleThreaded.h:59
virtual int GetMaxConcurrency() const override
Get maximum number of concurrently executing jobs.
Definition JobSystemSingleThreaded.h:27
JobSystemSingleThreaded(uint inMaxJobs)
Definition JobSystemSingleThreaded.h:20
JPH_OVERRIDE_NEW_DELETE JobSystemSingleThreaded()=default
Constructor.