aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2022-04-13 11:51:05 +0200
committerFawzi Mohamed <fawzi.mohamed@qt.io>2022-04-28 15:34:01 +0200
commit12d5d7d30613dd09cbdf4fba2decf282d3d8db39 (patch)
treef67aa52898296b7788d13c03ed4e231a027a45cb /tools
parent11d1466a7eabfb1b73b8e93abfe6a79e721f3de8 (diff)
qmlls: ensure proper shutdown on QQmmlCodeModel destructor
* fix counting of in progress index & updates * wait for index and open document update threads to end before deleting the code model * ensure that indexing stops as quickly as possible on shutdown Change-Id: I320e8950269381bfc77213bd8e34459b34b104b2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlls/qqmlcodemodel.cpp49
-rw-r--r--tools/qmlls/qqmlcodemodel.h3
2 files changed, 37 insertions, 15 deletions
diff --git a/tools/qmlls/qqmlcodemodel.cpp b/tools/qmlls/qqmlcodemodel.cpp
index f6d4cbf140..2a45a4d98e 100644
--- a/tools/qmlls/qqmlcodemodel.cpp
+++ b/tools/qmlls/qqmlcodemodel.cpp
@@ -107,6 +107,22 @@ QQmlCodeModel::QQmlCodeModel(QObject *parent)
{
}
+QQmlCodeModel::~QQmlCodeModel()
+{
+ while (true) {
+ bool shouldWait;
+ {
+ QMutexLocker l(&m_mutex);
+ m_state = State::Stopping;
+ m_openDocumentsToUpdate.clear();
+ shouldWait = m_nIndexInProgress != 0 || m_nUpdateInProgress != 0;
+ }
+ if (!shouldWait)
+ break;
+ QThread::yieldCurrentThread();
+ }
+}
+
OpenDocumentSnapshot QQmlCodeModel::snapshotByUri(const QByteArray &uri)
{
return openDocumentByUri(uri).snapshot;
@@ -135,7 +151,6 @@ void QQmlCodeModel::indexEnd()
qCDebug(codeModelLog) << "indexEnd";
m_lastIndexProgress = 0;
m_nIndexInProgress = 0;
- m_nUpdateInProgress = 0;
m_toIndex.clear();
m_indexInProgressCost = 0;
m_indexDoneCost = 0;
@@ -151,6 +166,9 @@ void QQmlCodeModel::indexSendProgress(int progress)
bool QQmlCodeModel::indexCancelled()
{
+ QMutexLocker l(&m_mutex);
+ if (m_state == State::Stopping)
+ return true;
return false;
}
@@ -215,9 +233,7 @@ void QQmlCodeModel::addDirectory(const QString &path, int depthLeft)
return;
{
QMutexLocker l(&m_mutex);
- auto it = m_toIndex.begin();
- auto end = m_toIndex.end();
- while (it != end) {
+ for (auto it = m_toIndex.begin(); it != m_toIndex.end();) {
if (it->path.startsWith(path)) {
if (it->path.size() == path.size())
return;
@@ -227,6 +243,7 @@ void QQmlCodeModel::addDirectory(const QString &path, int depthLeft)
}
} else if (path.startsWith(it->path) && path.at(it->path.size()) == u'/')
return;
+ ++it;
}
m_toIndex.append({ path, depthLeft });
}
@@ -329,17 +346,19 @@ bool QQmlCodeModel::indexSome()
m_toIndex.removeLast();
}
bool hasMore = false;
- auto guard = qScopeGuard([this, &hasMore]() {
- QMutexLocker l(&m_mutex);
- if (m_toIndex.isEmpty()) {
- if (--m_nIndexInProgress == 0)
- indexEnd();
- hasMore = false;
- } else {
- hasMore = true;
- }
- });
- indexDirectory(toIndex.path, toIndex.leftDepth);
+ {
+ auto guard = qScopeGuard([this, &hasMore]() {
+ QMutexLocker l(&m_mutex);
+ if (m_toIndex.isEmpty()) {
+ if (--m_nIndexInProgress == 0)
+ indexEnd();
+ hasMore = false;
+ } else {
+ hasMore = true;
+ }
+ });
+ indexDirectory(toIndex.path, toIndex.leftDepth);
+ }
return hasMore;
}
diff --git a/tools/qmlls/qqmlcodemodel.h b/tools/qmlls/qqmlcodemodel.h
index a0daaaa9f6..cf7a3cacbe 100644
--- a/tools/qmlls/qqmlcodemodel.h
+++ b/tools/qmlls/qqmlcodemodel.h
@@ -84,8 +84,10 @@ class QQmlCodeModel : public QObject
Q_OBJECT
public:
enum class UriLookup { Caching, ForceLookup };
+ enum class State { Running, Stopping };
explicit QQmlCodeModel(QObject *parent = nullptr);
+ ~QQmlCodeModel();
QQmlJS::Dom::DomItem currentEnv();
QQmlJS::Dom::DomItem validEnv();
OpenDocumentSnapshot snapshotByUri(const QByteArray &uri);
@@ -117,6 +119,7 @@ private:
void openUpdateEnd();
void openUpdate(const QByteArray &);
mutable QMutex m_mutex;
+ State m_state = State::Running;
int m_lastIndexProgress = 0;
int m_nIndexInProgress = 0;
QList<ToIndex> m_toIndex;