diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-03-05 13:54:50 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-06-21 12:19:17 +0000 |
commit | fe7b5458eba417fee38e8cb8ea8060554df7c091 (patch) | |
tree | fd8fefe43c4e582ebc2a000613139641e2a8e6c2 /src/libs/qmljs/qmljsplugindumper.cpp | |
parent | aca55dce58baf4124f6a66a47b2deaf0ef47c9d0 (diff) |
Refactor tst_joinAllThreads, to be used in ModelManager d'tor
The idea in this approach is that we only collect those futures,
which have resulted from runAsync. The assumption is that
all tasks associated with those futures may sooner or
later finish, without the need to call qApp->processEvents().
OTOH, we don't collect fake futures coming from Utils::onFinished,
as these requires the spinning event loop in order to deliver
the onFinished signal.
So, the new joinAllThreads() method waits for all collected
futures to finish. We also _do_ want canceled and not finished
futures to finish, since even when they are canceled,
they may still be running and using the internals
of possibly destructed ModelManager. This means, we are only
waiting for other threads to be finished, without reporting
their results to e.g. onFinished() handlers.
Some tests require that all onFinished handlers are also processed.
In order to achieve this, we create a loop inside
tst_joinAllThreads() method and we call joinAllThreads(), so
it will wait for all pending queue to finish, and then we call process
events, in order to let finished futures propagate their results
to their respective onFinished() handlers.
Some handlers may have stared another threads when being processed,
so we may expect that some new futures will appear.
So, after processing the events we check if any new events
appeared, and in this case we repeat the loop.
Otherwise, we finish synchronization.
Amends: 96c860159b862460e21be16a6e2839c0b591e016
Task-number: QTCREATORBUG-25350
Change-Id: I5e44150c55f6be00445a5695938482d948990c94
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
Diffstat (limited to 'src/libs/qmljs/qmljsplugindumper.cpp')
-rw-r--r-- | src/libs/qmljs/qmljsplugindumper.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/libs/qmljs/qmljsplugindumper.cpp b/src/libs/qmljs/qmljsplugindumper.cpp index a98f7550d6..376166559f 100644 --- a/src/libs/qmljs/qmljsplugindumper.cpp +++ b/src/libs/qmljs/qmljsplugindumper.cpp @@ -300,9 +300,10 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode) QLatin1String("<dump of ") + libraryPath + QLatin1Char('>')); future.reportFinished(&infos); }); + m_modelManager->addFuture(future); - auto finalFuture = Utils::onFinished(future, this, - [this, libraryInfo, privatePlugin, libraryPath] (const QFuture<CppQmlTypesInfo>& future) { + Utils::onFinished(future, this, [this, libraryInfo, privatePlugin, libraryPath] + (const QFuture<CppQmlTypesInfo>& future) { CppQmlTypesInfo infos = future.result(); LibraryInfo libInfo = libraryInfo; @@ -325,7 +326,6 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode) m_modelManager->updateLibraryInfo(libraryPath, libInfo); }); - m_modelManager->addFuture(finalFuture); } else { libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpDone); libraryInfo.updateFingerprint(); @@ -395,6 +395,7 @@ QFuture<PluginDumper::QmlTypeDescription> PluginDumper::loadQmlTypeDescription(c future.reportFinished(&result); }); + m_modelManager->addFuture(future); return future; } @@ -598,12 +599,12 @@ void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths, const QString &libraryPath, QmlJS::LibraryInfo libraryInfo) { - auto future = Utils::onFinished(loadQmlTypeDescription(qmltypesFilePaths), this, [=](const QFuture<PluginDumper::QmlTypeDescription> &typesFuture) + Utils::onFinished(loadQmlTypeDescription(qmltypesFilePaths), this, [=](const QFuture<PluginDumper::QmlTypeDescription> &typesFuture) { PluginDumper::QmlTypeDescription typesResult = typesFuture.result(); if (!typesResult.dependencies.isEmpty()) { - auto depFuture = Utils::onFinished(loadDependencies(typesResult.dependencies, QSharedPointer<QSet<QString>>()), this, + Utils::onFinished(loadDependencies(typesResult.dependencies, QSharedPointer<QSet<QString>>()), this, [typesResult, libraryInfo, libraryPath, this] (const QFuture<PluginDumper::DependencyInfo> &loadFuture) { PluginDumper::DependencyInfo loadResult = loadFuture.result(); @@ -621,7 +622,6 @@ void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths, typesResult.moduleApis, objects); m_modelManager->updateLibraryInfo(libraryPath, libInfo); }); - m_modelManager->addFuture(depFuture); } else { QmlJS::LibraryInfo libInfo = libraryInfo; prepareLibraryInfo(libInfo, libraryPath, typesResult.dependencies, @@ -630,7 +630,6 @@ void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths, m_modelManager->updateLibraryInfo(libraryPath, libInfo); } }); - m_modelManager->addFuture(future); } void PluginDumper::runQmlDump(const QmlJS::ModelManagerInterface::ProjectInfo &info, |