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>
This commit is contained in:
parent
1823c1c6d7
commit
3b14f29b8e
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue