aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewfileengine.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-08-16 15:02:40 +0200
committerTarja Sundqvist <tarja.sundqvist@qt.io>2021-08-23 16:57:47 +0300
commiteaf011c4ae440bbf7a02ceb7a33be5dfa5bcf907 (patch)
tree5d8544db19f78517c48f8495a8a6d7a0cfd3e0f2 /src/plugins/qmltooling/qmldbg_preview/qqmlpreviewfileengine.cpp
parenta18926c736bf9de6bd652c8bb1799d4678001341 (diff)
QmlPreview: Protect QQmlPreviewFileLoader::load with another mutex
We can concurrently load multiple files from different threads, but the loader can only handle one such request at a time. Fixes: QTBUG-95825 Change-Id: I2b94d55f2cf0da6e84dabc47df5699cc57b903a6 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Knud Dollereder <knud.dollereder@qt.io> (cherry picked from commit a068fdc0b2cf7d4223d9ad15345fe9d345875936) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/plugins/qmltooling/qmldbg_preview/qqmlpreviewfileengine.cpp')
-rw-r--r--src/plugins/qmltooling/qmldbg_preview/qqmlpreviewfileengine.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewfileengine.cpp b/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewfileengine.cpp
index 620c1cf1ba..7b53402df9 100644
--- a/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewfileengine.cpp
+++ b/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewfileengine.cpp
@@ -398,6 +398,14 @@ bool QQmlPreviewFileEngine::supportsExtension(Extension extension) const
void QQmlPreviewFileEngine::load() const
{
+ // We can get here from different threads on different instances of QQmlPreviewFileEngine.
+ // However, there is only one loader per QQmlPreviewFileEngineHandler and it is not thread-safe.
+ // Its content mutex doesn't help us here because we explicitly wait on it in load(), which
+ // causes it to be released. Therefore, lock the load mutex first.
+ // This doesn't cause any deadlocks because the only thread that wakes the loader on the content
+ // mutex never calls load(). It's the QML debug server thread that handles the debug protocol.
+ QMutexLocker loadLocker(m_loader->loadMutex());
+
m_result = m_loader->load(m_absolute);
switch (m_result) {
case QQmlPreviewFileLoader::File: