Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Core/JobSystemSingleThreaded.cpp
10279 views
1
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2
// SPDX-FileCopyrightText: 2023 Jorrit Rouwe
3
// SPDX-License-Identifier: MIT
4
5
#include <Jolt/Jolt.h>
6
7
#include <Jolt/Core/JobSystemSingleThreaded.h>
8
9
JPH_NAMESPACE_BEGIN
10
11
void JobSystemSingleThreaded::Init(uint inMaxJobs)
12
{
13
mJobs.Init(inMaxJobs, inMaxJobs);
14
}
15
16
JobHandle JobSystemSingleThreaded::CreateJob(const char *inJobName, ColorArg inColor, const JobFunction &inJobFunction, uint32 inNumDependencies)
17
{
18
// Construct an object
19
uint32 index = mJobs.ConstructObject(inJobName, inColor, this, inJobFunction, inNumDependencies);
20
JPH_ASSERT(index != AvailableJobs::cInvalidObjectIndex);
21
Job *job = &mJobs.Get(index);
22
23
// Construct handle to keep a reference, the job is queued below and will immediately complete
24
JobHandle handle(job);
25
26
// If there are no dependencies, queue the job now
27
if (inNumDependencies == 0)
28
QueueJob(job);
29
30
// Return the handle
31
return handle;
32
}
33
34
void JobSystemSingleThreaded::FreeJob(Job *inJob)
35
{
36
mJobs.DestructObject(inJob);
37
}
38
39
void JobSystemSingleThreaded::QueueJob(Job *inJob)
40
{
41
inJob->Execute();
42
}
43
44
void JobSystemSingleThreaded::QueueJobs(Job **inJobs, uint inNumJobs)
45
{
46
for (uint i = 0; i < inNumJobs; ++i)
47
QueueJob(inJobs[i]);
48
}
49
50
JobSystem::Barrier *JobSystemSingleThreaded::CreateBarrier()
51
{
52
return &mDummyBarrier;
53
}
54
55
void JobSystemSingleThreaded::DestroyBarrier(Barrier *inBarrier)
56
{
57
// There's nothing to do here, the barrier is just a dummy
58
}
59
60
void JobSystemSingleThreaded::WaitForJobs(Barrier *inBarrier)
61
{
62
// There's nothing to do here, the barrier is just a dummy, we just execute the jobs immediately
63
}
64
65
JPH_NAMESPACE_END
66
67