MultithreadedTest.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Tests/Test.h>
  6. class MultithreadedTest : public Test
  7. {
  8. public:
  9. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, MultithreadedTest)
  10. // Description of the test
  11. virtual const char * GetDescription() const override
  12. {
  13. return "This test spawns boxes and ragdolls and performs ray cast tests from threads / jobs to see if the simulation is thread safe.";
  14. }
  15. // Destructor
  16. virtual ~MultithreadedTest() override;
  17. // Number used to scale the terrain and camera movement to the scene
  18. virtual float GetWorldScale() const override { return 0.2f; }
  19. // Initialization
  20. virtual void Initialize() override;
  21. // Test will never be deterministic since various threads are trying to concurrently add / remove bodies
  22. virtual bool IsDeterministic() const override { return false; }
  23. private:
  24. // Execute a lambda either on this thread or in a separate job
  25. void Execute(default_random_engine &ioRandom, const char *inName, function<void()> inFunction);
  26. // Thread main function that spawns boxes
  27. void BoxSpawner();
  28. // Thread main function that spawns ragdolls
  29. void RagdollSpawner();
  30. // Thread main function that casts rays
  31. void CasterMain();
  32. thread mBoxSpawnerThread;
  33. thread mRagdollSpawnerThread;
  34. thread mCasterThread;
  35. atomic<bool> mIsQuitting = false;
  36. };