aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2016-06-01 10:55:45 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-06-01 10:35:21 +0000
commit3b14f29b8e5b889c7682eaca3e750493a05bcdb8 (patch)
tree85af2a2714412cf3db4c8b6e65ccce9ad1300d2f
parent1823c1c6d75261cf0b3f247e07ac3d0c7b31f1c0 (diff)
Ensure that CompilationUnit instances are deleted in the engine thread
When using CompilationUnit with a QML engine, ensure that they are deleted in the same thread as the QML engine. Only the QML engine has a secondary thread (not a plain QJSEngine) and there it may happen that the last refcount drops within the loader thread. For example when the trimCache() is called within the loader. The destruction of the CompilationUnit however is not safe to perform in a secondary thread. Change-Id: Ia0105a8885ec97b0b2159e32e637adbd4e99f016 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
-rw-r--r--src/qml/compiler/qv4compileddata.cpp11
-rw-r--r--src/qml/compiler/qv4compileddata_p.h1
-rw-r--r--src/qml/qml/qqmlcompileddata.cpp8
-rw-r--r--src/qml/qml/qqmlcompiler_p.h3
4 files changed, 12 insertions, 11 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index 7a2404f40c..d4ed899d3e 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -222,6 +222,17 @@ void CompilationUnit::markObjects(QV4::ExecutionEngine *e)
}
}
+void CompilationUnit::destroy()
+{
+ QQmlEngine *qmlEngine = 0;
+ if (engine)
+ qmlEngine = engine->qmlEngine();
+ if (qmlEngine)
+ QQmlEnginePrivate::deleteInEngineThread(qmlEngine, this);
+ else
+ delete this;
+}
+
IdentifierHash<int> CompilationUnit::namedObjectsPerComponent(int componentObjectIndex)
{
auto it = namedObjectsPerComponentCache.find(componentObjectIndex);
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index cb4941d147..117bad0c8b 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -734,6 +734,7 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit : public QQmlRefCount
void markObjects(QV4::ExecutionEngine *e);
+ void destroy() Q_DECL_OVERRIDE;
protected:
virtual void linkBackendToEngine(QV4::ExecutionEngine *engine) = 0;
#endif // V4_BOOTSTRAP
diff --git a/src/qml/qml/qqmlcompileddata.cpp b/src/qml/qml/qqmlcompileddata.cpp
index 5344c738d8..1a9919c1be 100644
--- a/src/qml/qml/qqmlcompileddata.cpp
+++ b/src/qml/qml/qqmlcompileddata.cpp
@@ -60,14 +60,6 @@ QQmlCompiledData::QQmlCompiledData(QQmlEngine *engine)
Q_ASSERT(engine);
}
-void QQmlCompiledData::destroy()
-{
- if (engine && compilationUnit && compilationUnit->engine)
- QQmlEnginePrivate::deleteInEngineThread(engine, this);
- else
- delete this;
-}
-
QQmlCompiledData::~QQmlCompiledData()
{
}
diff --git a/src/qml/qml/qqmlcompiler_p.h b/src/qml/qml/qqmlcompiler_p.h
index 35beba1562..2846ae4084 100644
--- a/src/qml/qml/qqmlcompiler_p.h
+++ b/src/qml/qml/qqmlcompiler_p.h
@@ -91,9 +91,6 @@ public:
QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit;
-protected:
- virtual void destroy(); // From QQmlRefCount
-
private:
QQmlCompiledData(const QQmlCompiledData &other);
QQmlCompiledData &operator=(const QQmlCompiledData &other);