Path: blob/master/thirdparty/jolt_physics/Jolt/Core/JobSystemSingleThreaded.cpp
10279 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2023 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#include <Jolt/Jolt.h>56#include <Jolt/Core/JobSystemSingleThreaded.h>78JPH_NAMESPACE_BEGIN910void JobSystemSingleThreaded::Init(uint inMaxJobs)11{12mJobs.Init(inMaxJobs, inMaxJobs);13}1415JobHandle JobSystemSingleThreaded::CreateJob(const char *inJobName, ColorArg inColor, const JobFunction &inJobFunction, uint32 inNumDependencies)16{17// Construct an object18uint32 index = mJobs.ConstructObject(inJobName, inColor, this, inJobFunction, inNumDependencies);19JPH_ASSERT(index != AvailableJobs::cInvalidObjectIndex);20Job *job = &mJobs.Get(index);2122// Construct handle to keep a reference, the job is queued below and will immediately complete23JobHandle handle(job);2425// If there are no dependencies, queue the job now26if (inNumDependencies == 0)27QueueJob(job);2829// Return the handle30return handle;31}3233void JobSystemSingleThreaded::FreeJob(Job *inJob)34{35mJobs.DestructObject(inJob);36}3738void JobSystemSingleThreaded::QueueJob(Job *inJob)39{40inJob->Execute();41}4243void JobSystemSingleThreaded::QueueJobs(Job **inJobs, uint inNumJobs)44{45for (uint i = 0; i < inNumJobs; ++i)46QueueJob(inJobs[i]);47}4849JobSystem::Barrier *JobSystemSingleThreaded::CreateBarrier()50{51return &mDummyBarrier;52}5354void JobSystemSingleThreaded::DestroyBarrier(Barrier *inBarrier)55{56// There's nothing to do here, the barrier is just a dummy57}5859void JobSystemSingleThreaded::WaitForJobs(Barrier *inBarrier)60{61// There's nothing to do here, the barrier is just a dummy, we just execute the jobs immediately62}6364JPH_NAMESPACE_END656667