diff options
| author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2026-09-03 12:35:56 +0300 |
|---|---|---|
| committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2026-09-03 12:35:56 +0300 |
| commit | 7ed17317a5013b1ab885ecc4ac61fb0ed3c1ab35 (patch) | |
| tree | 7c208fe854d7dcfd7421c2ea20e3cd8a0812adfe /src/qmlworkerscript/qquickworkerscript.cpp | |
| parent | 175e30c1a74c2b4efa5a6fe5c45d289660b51d2f (diff) | |
| parent | 2d9e5e76640cd16724ec2fef20d60109537be0bd (diff) | |
Merge tag 'v6.5.10-lts-lgpl' into 6.56.5
Qt 6.5.10-lts-lgpl release
Diffstat (limited to 'src/qmlworkerscript/qquickworkerscript.cpp')
| -rw-r--r-- | src/qmlworkerscript/qquickworkerscript.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/qmlworkerscript/qquickworkerscript.cpp b/src/qmlworkerscript/qquickworkerscript.cpp index 8df631c6d3..40e4617382 100644 --- a/src/qmlworkerscript/qquickworkerscript.cpp +++ b/src/qmlworkerscript/qquickworkerscript.cpp @@ -194,6 +194,8 @@ bool QQuickWorkerScriptEnginePrivate::event(QEvent *event) QV4::ExecutionEngine *QQuickWorkerScriptEnginePrivate::workerEngine(int id) { + QMutexLocker locker(&m_lock); + const auto it = workers.find(id); if (it == workers.end()) return nullptr; @@ -347,19 +349,16 @@ QQmlError WorkerErrorEvent::error() const QQuickWorkerScriptEngine::QQuickWorkerScriptEngine(QQmlEngine *parent) : QThread(parent), d(new QQuickWorkerScriptEnginePrivate(parent)) { - d->m_lock.lock(); connect(d, SIGNAL(stopThread()), this, SLOT(quit()), Qt::DirectConnection); + QMutexLocker locker(&d->m_lock); start(QThread::LowestPriority); d->m_wait.wait(&d->m_lock); d->moveToThread(this); - d->m_lock.unlock(); } QQuickWorkerScriptEngine::~QQuickWorkerScriptEngine() { - d->m_lock.lock(); QCoreApplication::postEvent(d, new QEvent((QEvent::Type)QQuickWorkerScriptEnginePrivate::WorkerDestroyEvent)); - d->m_lock.unlock(); //We have to force to cleanup the main thread's event queue here //to make sure the main GUI release all pending locks/wait conditions which @@ -408,23 +407,26 @@ int QQuickWorkerScriptEngine::registerWorkerScript(QQuickWorkerScript *owner) { const int id = d->m_nextId++; - d->m_lock.lock(); + QMutexLocker locker(&d->m_lock); d->workers.insert(id, owner); - d->m_lock.unlock(); return id; } void QQuickWorkerScriptEngine::removeWorkerScript(int id) { - const auto it = d->workers.find(id); - if (it == d->workers.end()) - return; + { + QMutexLocker locker(&d->m_lock); + const auto it = d->workers.find(id); + if (it == d->workers.end()) + return; - if (it->isT1()) { - QV4::ExecutionEngine *engine = it->asT1(); - workerScriptExtension(engine)->owner = nullptr; + if (it->isT1()) + workerScriptExtension(it->asT1())->owner = nullptr; + else + *it = static_cast<QQuickWorkerScript *>(nullptr); } + QCoreApplication::postEvent(d, new WorkerRemoveEvent(id)); } @@ -440,12 +442,14 @@ void QQuickWorkerScriptEngine::sendMessage(int id, const QByteArray &data) void QQuickWorkerScriptEngine::run() { - d->m_lock.lock(); - d->m_wait.wakeAll(); - d->m_lock.unlock(); + { + QMutexLocker locker(&d->m_lock); + d->m_wait.wakeAll(); + } exec(); + QMutexLocker locker(&d->m_lock); for (auto it = d->workers.begin(), end = d->workers.end(); it != end; ++it) { if (it->isT1()) delete it->asT1(); |
