aboutsummaryrefslogtreecommitdiff
path: root/NvCloth/samples/SampleBase/utils/JobManager.cpp
diff options
context:
space:
mode:
authorMarijn Tamis <[email protected]>2018-05-03 18:22:48 +0200
committerMarijn Tamis <[email protected]>2018-05-03 18:22:48 +0200
commitca32c59a58d37c1822e185a2d5f3d0d3e8943593 (patch)
treeb06b9eec03f34344ef8fc31aa147b2714d3962ee /NvCloth/samples/SampleBase/utils/JobManager.cpp
parentForced rename of platform folders in cmake dir. Git didn't pick this up before. (diff)
downloadnvcloth-ca32c59a58d37c1822e185a2d5f3d0d3e8943593.tar.xz
nvcloth-ca32c59a58d37c1822e185a2d5f3d0d3e8943593.zip
NvCloth 1.1.4 Release. (24070740)
Diffstat (limited to 'NvCloth/samples/SampleBase/utils/JobManager.cpp')
-rw-r--r--NvCloth/samples/SampleBase/utils/JobManager.cpp19
1 files changed, 13 insertions, 6 deletions
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<std::mutex> 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<std::mutex> 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
{