Skip to content

Commit

Permalink
Traktor: Manually protected array of jobs in dependency scanner.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Jun 13, 2024
1 parent 3d71fe2 commit b2465ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
24 changes: 19 additions & 5 deletions code/Editor/Pipeline/PipelineDependsParallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ void PipelineDependsParallel::addDependency(const ISerializable* sourceAsset, co
jobAddDependency(parentDependency, sourceAssetRef, outputPath, outputGuid, flags);
});
if (job)
m_jobs.put(job);
{
T_ANONYMOUS_VAR(Acquire< Semaphore >)(m_jobsLock);
m_jobs.push_back(job);
}
else
m_result = false;
}
Expand All @@ -127,7 +130,10 @@ void PipelineDependsParallel::addDependency(db::Instance* sourceAssetInstance, u
jobAddDependency(parentDependency, sourceAssetInstanceRef, flags);
});
if (job)
m_jobs.put(job);
{
T_ANONYMOUS_VAR(Acquire< Semaphore >)(m_jobsLock);
m_jobs.push_back(job);
}
else
m_result = false;
}
Expand All @@ -146,7 +152,10 @@ void PipelineDependsParallel::addDependency(const Guid& sourceAssetGuid, uint32_
jobAddDependency(parentDependency, sourceAssetGuid, flags);
});
if (job)
m_jobs.put(job);
{
T_ANONYMOUS_VAR(Acquire< Semaphore >)(m_jobsLock);
m_jobs.push_back(job);
}
else
m_result = false;
}
Expand Down Expand Up @@ -212,8 +221,13 @@ bool PipelineDependsParallel::waitUntilFinished()
Ref< Job > job;
for (;;)
{
if (!m_jobs.get(job))
break;
{
T_ANONYMOUS_VAR(Acquire< Semaphore >)(m_jobsLock);
if (m_jobs.empty())
break;
job = m_jobs.front();
m_jobs.pop_front();
}
job->wait();
}
return m_result;
Expand Down
7 changes: 4 additions & 3 deletions code/Editor/Pipeline/PipelineDependsParallel.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once

#include "Core/Containers/ThreadsafeFifo.h"
#include "Core/RefArray.h"
#include "Core/Thread/ReaderWriterLock.h"
#include "Core/Thread/Semaphore.h"
#include "Core/Thread/ThreadLocal.h"
Expand Down Expand Up @@ -93,7 +93,7 @@ class T_DLLCLASS PipelineDependsParallel : public IPipelineDepends
virtual Ref< const ISerializable > getObjectReadOnly(const Guid& instanceGuid) override final;

private:
ThreadsafeFifo< Ref< Job > > m_jobs;
RefArray< Job > m_jobs;
Ref< PipelineFactory > m_pipelineFactory;
Ref< db::Database > m_sourceDatabase;
Ref< db::Database > m_outputDatabase;
Expand All @@ -102,6 +102,7 @@ class T_DLLCLASS PipelineDependsParallel : public IPipelineDepends
Ref< IPipelineInstanceCache > m_instanceCache;
ThreadLocal m_currentDependency;
ReaderWriterLock m_readCacheLock;
Semaphore m_jobsLock;
Semaphore m_dependencySetLock;
mutable bool m_result;

Expand Down

0 comments on commit b2465ba

Please sign in to comment.