CompilationDatabaseProjectManager: Fix unexpected double emit of signal

Do not rely on QFutureWatcher::isFinished(), which triggers a crash in
the plugin unit test with Qt 6 (race condition?).

Change-Id: I379d894ebd4a28a64b1e70e0cee6eef9ab720a14
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
(cherry picked from commit 32541fef3b)
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Christian Kandeler
2021-09-15 16:32:11 +02:00
committed by Eike Ziller
parent 8c30b29d76
commit 7c5a830111
2 changed files with 14 additions and 6 deletions

View File

@@ -59,8 +59,7 @@ CompilationDbParser::CompilationDbParser(const QString &projectName,
{ {
connect(&m_parserWatcher, &QFutureWatcher<void>::finished, this, [this] { connect(&m_parserWatcher, &QFutureWatcher<void>::finished, this, [this] {
m_dbContents = m_parserWatcher.result(); m_dbContents = m_parserWatcher.result();
if (!m_treeScanner || m_treeScanner->isFinished()) parserJobFinished();
finish(ParseResult::Success);
}); });
} }
@@ -80,6 +79,7 @@ void CompilationDbParser::start()
return; return;
} }
m_projectFileHash = newHash; m_projectFileHash = newHash;
m_runningParserJobs = 0;
// Thread 1: Scan disk. // Thread 1: Scan disk.
if (!m_rootPath.isEmpty()) { if (!m_rootPath.isEmpty()) {
@@ -109,10 +109,9 @@ void CompilationDbParser::start()
Core::ProgressManager::addTask(m_treeScanner->future(), Core::ProgressManager::addTask(m_treeScanner->future(),
tr("Scan \"%1\" project tree").arg(m_projectName), tr("Scan \"%1\" project tree").arg(m_projectName),
"CompilationDatabase.Scan.Tree"); "CompilationDatabase.Scan.Tree");
connect(m_treeScanner, &TreeScanner::finished, this, [this] { ++m_runningParserJobs;
if (m_parserWatcher.isFinished()) connect(m_treeScanner, &TreeScanner::finished,
finish(ParseResult::Success); this, &CompilationDbParser::parserJobFinished);
});
} }
// Thread 2: Parse the project file. // Thread 2: Parse the project file.
@@ -120,6 +119,7 @@ void CompilationDbParser::start()
Core::ProgressManager::addTask(future, Core::ProgressManager::addTask(future,
tr("Parse \"%1\" project").arg(m_projectName), tr("Parse \"%1\" project").arg(m_projectName),
"CompilationDatabase.Parse"); "CompilationDatabase.Parse");
++m_runningParserJobs;
m_parserWatcher.setFuture(future); m_parserWatcher.setFuture(future);
} }
@@ -143,6 +143,12 @@ QList<FileNode *> CompilationDbParser::scannedFiles() const
: QList<FileNode *>(); : QList<FileNode *>();
} }
void CompilationDbParser::parserJobFinished()
{
if (--m_runningParserJobs == 0)
finish(ParseResult::Success);
}
void CompilationDbParser::finish(ParseResult result) void CompilationDbParser::finish(ParseResult result)
{ {
emit finished(result); emit finished(result);

View File

@@ -77,6 +77,7 @@ signals:
void finished(ParseResult result); void finished(ParseResult result);
private: private:
void parserJobFinished();
void finish(ParseResult result); void finish(ParseResult result);
DbContents parseProject(); DbContents parseProject();
std::vector<DbEntry> readJsonObjects() const; std::vector<DbEntry> readJsonObjects() const;
@@ -90,6 +91,7 @@ private:
DbContents m_dbContents; DbContents m_dbContents;
QByteArray m_projectFileContents; QByteArray m_projectFileContents;
QByteArray m_projectFileHash; QByteArray m_projectFileHash;
int m_runningParserJobs = 0;
ProjectExplorer::BuildSystem::ParseGuard m_guard; ProjectExplorer::BuildSystem::ParseGuard m_guard;
}; };