ModelManagerInterface: Cancel all running threads on session switch

On session switch we cancel all the running tasks.
We connect to the SessionManager::aboutToLoadSession()
signal, as this one is emitted just before loading
new session's projects. We don't connect to
SessionManager::aboutToUnloadSession(), since after
this signal is emitted the unloading may be canceled
due to e.g. showing the dialog asking for saving
changed files in the unloaded session (the user may
cancel the process of unloading).

In contrast to what we do on shutdown, we don't wait
for futures being finished here - it's just enough we
cancel all of them.

Fixes: QTCREATORBUG-25583
Change-Id: I01eeca00d150f6e98a80a050c6a19efb848b9954
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2021-04-19 14:50:51 +02:00
parent 5639c141ff
commit 91c1c244a1
3 changed files with 14 additions and 1 deletions

View File

@@ -317,6 +317,16 @@ void ModelManagerInterface::setDefaultProject(const ModelManagerInterface::Proje
}); });
} }
void ModelManagerInterface::cancelAllThreads()
{
m_cppQmlTypesUpdater.cancel();
// Don't execute the scheduled updates for the old session anymore
m_updateCppQmlTypesTimer->stop();
m_asyncResetTimer->stop();
QMutexLocker locker(&m_futuresMutex);
m_futureSynchronizer.cancelAllFutures();
}
Snapshot ModelManagerInterface::snapshot() const Snapshot ModelManagerInterface::snapshot() const
{ {
return m_syncedData.readLocked()->m_validSnapshot; return m_syncedData.readLocked()->m_validSnapshot;

View File

@@ -238,7 +238,7 @@ protected:
void updateImportPaths(); void updateImportPaths();
void loadQmlTypeDescriptionsInternal(const QString &path); void loadQmlTypeDescriptionsInternal(const QString &path);
void setDefaultProject(const ProjectInfo &pInfo, ProjectExplorer::Project *p); void setDefaultProject(const ProjectInfo &pInfo, ProjectExplorer::Project *p);
void cancelAllThreads();
private: private:
void joinAllThreads(bool cancelOnWait = false); void joinAllThreads(bool cancelOnWait = false);
void iterateQrcFiles(ProjectExplorer::Project *project, void iterateQrcFiles(ProjectExplorer::Project *project,

View File

@@ -10,6 +10,7 @@
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/messagemanager.h> #include <coreplugin/messagemanager.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/session.h>
#include <cppeditor/cppmodelmanager.h> #include <cppeditor/cppmodelmanager.h>
@@ -281,6 +282,8 @@ void ModelManager::delayedInitialization()
this, &ModelManager::removeProjectInfo); this, &ModelManager::removeProjectInfo);
connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged,
this, &ModelManager::updateDefaultProjectInfo); this, &ModelManager::updateDefaultProjectInfo);
connect(SessionManager::instance(), &SessionManager::aboutToLoadSession,
this, &ModelManager::cancelAllThreads);
ViewerContext qbsVContext; ViewerContext qbsVContext;
qbsVContext.language = Dialect::QmlQbs; qbsVContext.language = Dialect::QmlQbs;