From ca32c59a58d37c1822e185a2d5f3d0d3e8943593 Mon Sep 17 00:00:00 2001 From: Marijn Tamis Date: Thu, 3 May 2018 18:22:48 +0200 Subject: NvCloth 1.1.4 Release. (24070740) --- NvCloth/samples/SampleBase/utils/JobManager.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'NvCloth/samples/SampleBase/utils/JobManager.cpp') diff --git a/NvCloth/samples/SampleBase/utils/JobManager.cpp b/NvCloth/samples/SampleBase/utils/JobManager.cpp index 2a18d1c..a1e8454 100644 --- a/NvCloth/samples/SampleBase/utils/JobManager.cpp +++ b/NvCloth/samples/SampleBase/utils/JobManager.cpp @@ -41,9 +41,10 @@ void Job::Execute() else ExecuteInternal(); - mFinishedLock.lock(); - mFinished = true; - mFinishedLock.unlock(); + { + std::lock_guard lock(mFinishedLock); + mFinished = true; + } mFinishedEvent.notify_one(); } @@ -53,16 +54,19 @@ void Job::AddReference() } void Job::RemoveReference() { - if (0 == --mRefCount) + int refCount = --mRefCount; + if (0 == refCount) { mParent->Submit(this); } + assert(refCount >= 0); } void Job::Wait() { std::unique_lock lock(mFinishedLock); mFinishedEvent.wait(lock, [this](){return mFinished;} ); + lock.unlock(); return; } @@ -115,9 +119,12 @@ void MultithreadedSolverHelper::StartSimulation(float dt) if (mSolver->getSimulationChunkCount() != mSimulationChunkJobs.size()) { - mSimulationChunkJobs.resize(mSolver->getSimulationChunkCount(), Job()); + mSimulationChunkJobs.resize(mSolver->getSimulationChunkCount(), JobDependency()); for (int j = 0; j < mSolver->getSimulationChunkCount(); j++) - mSimulationChunkJobs[j].Initialize(mJobManager, [this, j](Job*) {mSolver->simulateChunk(j); mEndSimulationJob.RemoveReference(); }); + { + mSimulationChunkJobs[j].Initialize(mJobManager, [this, j](Job*) {mSolver->simulateChunk(j); }); + mSimulationChunkJobs[j].SetDependentJob(&mEndSimulationJob); + } } else { -- cgit v1.2.3