Refactor the lifetime of future watcher inside QmakeProFile

Create future watcher only prior to starting an async task.
After the task is done, clean the watcher in order to release
the resources kept inside its QFuture's result.

Make setupFutureWatcher() a private member. Provide
a corresponding cleanupFutureWatcher().

Change-Id: I9d2b058250a3f749a2c9ad51323d2d38f66ee98d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2021-10-25 11:18:49 +02:00
parent b5fd63b431
commit 2ac65f863b
2 changed files with 24 additions and 23 deletions

View File

@@ -1174,7 +1174,6 @@ QByteArray QmakeProFile::cxxDefines() const
QmakeProFile::QmakeProFile(QmakeBuildSystem *buildSystem, const FilePath &filePath) : QmakeProFile::QmakeProFile(QmakeBuildSystem *buildSystem, const FilePath &filePath) :
QmakePriFile(buildSystem, this, filePath) QmakePriFile(buildSystem, this, filePath)
{ {
setupFutureWatcher();
} }
QmakeProFile::QmakeProFile(const FilePath &filePath) : QmakePriFile(filePath) { } QmakeProFile::QmakeProFile(const FilePath &filePath) : QmakePriFile(filePath) { }
@@ -1182,22 +1181,33 @@ QmakeProFile::QmakeProFile(const FilePath &filePath) : QmakePriFile(filePath) {
QmakeProFile::~QmakeProFile() QmakeProFile::~QmakeProFile()
{ {
qDeleteAll(m_extraCompilers); qDeleteAll(m_extraCompilers);
if (m_parseFutureWatcher) { cleanupFutureWatcher();
cleanupProFileReaders();
}
void QmakeProFile::cleanupFutureWatcher()
{
if (!m_parseFutureWatcher)
return;
m_parseFutureWatcher->disconnect();
m_parseFutureWatcher->cancel(); m_parseFutureWatcher->cancel();
m_parseFutureWatcher->waitForFinished(); m_parseFutureWatcher->waitForFinished();
if (m_readerExact) m_parseFutureWatcher->deleteLater();
applyAsyncEvaluate(false); m_parseFutureWatcher = nullptr;
delete m_parseFutureWatcher; m_buildSystem->decrementPendingEvaluateFutures();
}
cleanupProFileReaders();
} }
void QmakeProFile::setupFutureWatcher() void QmakeProFile::setupFutureWatcher()
{ {
QTC_ASSERT(!m_parseFutureWatcher, return);
m_parseFutureWatcher = new QFutureWatcher<Internal::QmakeEvalResultPtr>; m_parseFutureWatcher = new QFutureWatcher<Internal::QmakeEvalResultPtr>;
QObject::connect(m_parseFutureWatcher, &QFutureWatcherBase::finished, [this]() { QObject::connect(m_parseFutureWatcher, &QFutureWatcherBase::finished, [this]() {
applyAsyncEvaluate(true); applyEvaluate(m_parseFutureWatcher->result());
cleanupFutureWatcher();
}); });
m_buildSystem->incrementPendingEvaluateFutures();
} }
bool QmakeProFile::isParent(QmakeProFile *node) bool QmakeProFile::isParent(QmakeProFile *node)
@@ -1286,11 +1296,11 @@ void QmakeProFile::scheduleUpdate(QmakeProFile::AsyncUpdateDelay delay)
void QmakeProFile::asyncUpdate() void QmakeProFile::asyncUpdate()
{ {
m_buildSystem->incrementPendingEvaluateFutures(); cleanupFutureWatcher();
setupFutureWatcher();
setupReader(); setupReader();
if (!includedInExactParse()) if (!includedInExactParse())
m_readerExact->setExact(false); m_readerExact->setExact(false);
m_parseFutureWatcher->waitForFinished();
QmakeEvalInput input = evalInput(); QmakeEvalInput input = evalInput();
QFuture<QmakeEvalResultPtr> future = Utils::runAsync(ProjectExplorerPlugin::sharedThreadPool(), QFuture<QmakeEvalResultPtr> future = Utils::runAsync(ProjectExplorerPlugin::sharedThreadPool(),
QThread::LowestPriority, QThread::LowestPriority,
@@ -1640,13 +1650,6 @@ void QmakeProFile::asyncEvaluate(QFutureInterface<QmakeEvalResultPtr> &fi, Qmake
fi.reportResult(evaluate(input)); fi.reportResult(evaluate(input));
} }
void QmakeProFile::applyAsyncEvaluate(bool apply)
{
if (apply)
applyEvaluate(m_parseFutureWatcher->result());
m_buildSystem->decrementPendingEvaluateFutures();
}
bool sortByParserNodes(Node *a, Node *b) bool sortByParserNodes(Node *a, Node *b)
{ {
return a->filePath() < b->filePath(); return a->filePath() < b->filePath();
@@ -1720,7 +1723,6 @@ void QmakeProFile::applyEvaluate(const QmakeEvalResultPtr &result)
for (QmakeProFile * const proFile : qAsConst(result->proFiles)) { for (QmakeProFile * const proFile : qAsConst(result->proFiles)) {
proFile->finishInitialization(m_buildSystem, proFile); proFile->finishInitialization(m_buildSystem, proFile);
proFile->setupFutureWatcher();
proFile->asyncUpdate(); proFile->asyncUpdate();
} }
QmakePriFile::update(result->includedFiles.result); QmakePriFile::update(result->includedFiles.result);

View File

@@ -306,8 +306,6 @@ public:
explicit QmakeProFile(const Utils::FilePath &filePath); explicit QmakeProFile(const Utils::FilePath &filePath);
~QmakeProFile() override; ~QmakeProFile() override;
void setupFutureWatcher();
bool isParent(QmakeProFile *node); bool isParent(QmakeProFile *node);
QString displayName() const final; QString displayName() const final;
@@ -351,11 +349,12 @@ public:
bool isFileFromWildcard(const QString &filePath) const; bool isFileFromWildcard(const QString &filePath) const;
private: private:
void cleanupFutureWatcher();
void setupFutureWatcher();
void setParseInProgress(bool b); void setParseInProgress(bool b);
void setValidParseRecursive(bool b); void setValidParseRecursive(bool b);
void applyAsyncEvaluate(bool apply);
void setupReader(); void setupReader();
Internal::QmakeEvalInput evalInput() const; Internal::QmakeEvalInput evalInput() const;