diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2018-02-07 15:57:15 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-02-16 09:36:08 +0000 |
commit | 33006868d9d1bf1bee214f6d55c2cafde3cd2e3a (patch) | |
tree | 3658b5dfa5be9b70a5becbef5c899860145cf050 /src/lib/corelib/buildgraph/productbuilddata.cpp | |
parent | 24471740f276fc7fb3b662bd18ae637127368a9f (diff) |
Fix race condition when accessing the artifacts map from JavaScript
JavaScript commands, which potentially read the artifacts map, can run
concurrently to another rule's outputArtifacts script, which writes the
data structure backing said artifacts map. Therefore, we need to
synchronize the accesses to that data structure.
Note: While this fixes the undefined behavior on the language level
(i.e. no crashes), rule authors still need to ensure the artifacts they
are interested in are present already, e.g. by using suitable input
tags.
Change-Id: Id50d0b926975be7b734366cae4cad9cac6ec36a6
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/lib/corelib/buildgraph/productbuilddata.cpp')
-rw-r--r-- | src/lib/corelib/buildgraph/productbuilddata.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib/corelib/buildgraph/productbuilddata.cpp b/src/lib/corelib/buildgraph/productbuilddata.cpp index 8369bc762..f6cea4828 100644 --- a/src/lib/corelib/buildgraph/productbuilddata.cpp +++ b/src/lib/corelib/buildgraph/productbuilddata.cpp @@ -86,6 +86,7 @@ void ProductBuildData::store(PersistentPool &pool) const void ProductBuildData::addArtifactToSet(Artifact *artifact) { + std::lock_guard<std::mutex> l(m_artifactsMapMutex); for (const FileTag &tag : artifact->fileTags()) { m_artifactsByFileTag[tag] += artifact; m_jsArtifactsMapUpToDate = false; @@ -101,6 +102,7 @@ void ProductBuildData::removeArtifact(Artifact *artifact) void ProductBuildData::removeArtifactFromSetByFileTag(Artifact *artifact, const FileTag &fileTag) { + std::lock_guard<std::mutex> l(m_artifactsMapMutex); const auto it = m_artifactsByFileTag.find(fileTag); if (it == m_artifactsByFileTag.end()) return; @@ -112,6 +114,7 @@ void ProductBuildData::removeArtifactFromSetByFileTag(Artifact *artifact, const void ProductBuildData::addFileTagToArtifact(Artifact *artifact, const FileTag &tag) { + std::lock_guard<std::mutex> l(m_artifactsMapMutex); m_artifactsByFileTag[tag] += artifact; m_jsArtifactsMapUpToDate = false; } @@ -137,6 +140,12 @@ bool ProductBuildData::ruleHasArtifactWithChangedInputs(const RuleConstPtr &rule return !m_artifactsWithChangedInputsPerRule.value(rule).empty(); } +ArtifactSetByFileTag ProductBuildData::artifactsByFileTag() const +{ + std::lock_guard<std::mutex> l(m_artifactsMapMutex); + return m_artifactsByFileTag; +} + void ProductBuildData::setRescuableArtifactData(const AllRescuableArtifactData &rad) { m_rescuableArtifactData = rad; |