JobSystemSingleThreaded.cpp 1.6 KB

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