forked from qt-creator/qt-creator
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:
committed by
Eike Ziller
parent
8c30b29d76
commit
7c5a830111
@@ -59,8 +59,7 @@ CompilationDbParser::CompilationDbParser(const QString &projectName,
|
||||
{
|
||||
connect(&m_parserWatcher, &QFutureWatcher<void>::finished, this, [this] {
|
||||
m_dbContents = m_parserWatcher.result();
|
||||
if (!m_treeScanner || m_treeScanner->isFinished())
|
||||
finish(ParseResult::Success);
|
||||
parserJobFinished();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,6 +79,7 @@ void CompilationDbParser::start()
|
||||
return;
|
||||
}
|
||||
m_projectFileHash = newHash;
|
||||
m_runningParserJobs = 0;
|
||||
|
||||
// Thread 1: Scan disk.
|
||||
if (!m_rootPath.isEmpty()) {
|
||||
@@ -109,10 +109,9 @@ void CompilationDbParser::start()
|
||||
Core::ProgressManager::addTask(m_treeScanner->future(),
|
||||
tr("Scan \"%1\" project tree").arg(m_projectName),
|
||||
"CompilationDatabase.Scan.Tree");
|
||||
connect(m_treeScanner, &TreeScanner::finished, this, [this] {
|
||||
if (m_parserWatcher.isFinished())
|
||||
finish(ParseResult::Success);
|
||||
});
|
||||
++m_runningParserJobs;
|
||||
connect(m_treeScanner, &TreeScanner::finished,
|
||||
this, &CompilationDbParser::parserJobFinished);
|
||||
}
|
||||
|
||||
// Thread 2: Parse the project file.
|
||||
@@ -120,6 +119,7 @@ void CompilationDbParser::start()
|
||||
Core::ProgressManager::addTask(future,
|
||||
tr("Parse \"%1\" project").arg(m_projectName),
|
||||
"CompilationDatabase.Parse");
|
||||
++m_runningParserJobs;
|
||||
m_parserWatcher.setFuture(future);
|
||||
}
|
||||
|
||||
@@ -143,6 +143,12 @@ QList<FileNode *> CompilationDbParser::scannedFiles() const
|
||||
: QList<FileNode *>();
|
||||
}
|
||||
|
||||
void CompilationDbParser::parserJobFinished()
|
||||
{
|
||||
if (--m_runningParserJobs == 0)
|
||||
finish(ParseResult::Success);
|
||||
}
|
||||
|
||||
void CompilationDbParser::finish(ParseResult result)
|
||||
{
|
||||
emit finished(result);
|
||||
|
@@ -77,6 +77,7 @@ signals:
|
||||
void finished(ParseResult result);
|
||||
|
||||
private:
|
||||
void parserJobFinished();
|
||||
void finish(ParseResult result);
|
||||
DbContents parseProject();
|
||||
std::vector<DbEntry> readJsonObjects() const;
|
||||
@@ -90,6 +91,7 @@ private:
|
||||
DbContents m_dbContents;
|
||||
QByteArray m_projectFileContents;
|
||||
QByteArray m_projectFileHash;
|
||||
int m_runningParserJobs = 0;
|
||||
|
||||
ProjectExplorer::BuildSystem::ParseGuard m_guard;
|
||||
};
|
||||
|
Reference in New Issue
Block a user