diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2019-03-28 13:42:06 +0200 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2019-03-29 04:33:49 +0000 |
commit | 72bd8b9282b5256ef77a15da060a3b7cf2e99460 (patch) | |
tree | 13a58dc3113dc979e8e17a2365fe2d637f1db7b5 /src/runtime | |
parent | 08e3bba053ae329a53bf5b610c2fcde15aeefa3d (diff) |
Clean up the async loading fix a bit
Reduce unnecessary mutex locking in synchronous case.
Task-number: QT3DS-3226
Change-Id: I8990b7809a2e5914a7ec80d7500a8f5247870f86
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/runtime')
-rw-r--r-- | src/runtime/q3dsengine.cpp | 38 | ||||
-rw-r--r-- | src/runtime/q3dsengine_p.h | 4 |
2 files changed, 32 insertions, 10 deletions
diff --git a/src/runtime/q3dsengine.cpp b/src/runtime/q3dsengine.cpp index ef72f00..2e568b0 100644 --- a/src/runtime/q3dsengine.cpp +++ b/src/runtime/q3dsengine.cpp @@ -107,6 +107,12 @@ static QStringList q3ds_msg_buf; static QtMessageHandler q3ds_prev_msg_handler = nullptr; static Q3DSEngine *q3ds_msg_engine = nullptr; +static bool isAsyncLoadingEnabled() +{ + static bool enabled = (qEnvironmentVariableIntValue("Q3DS_ASYNC_LOADING")) > 0; + return enabled; +} + void Q3DSEngine::clearLog() { QMutexLocker locker(&q3ds_msg_mutex); @@ -172,6 +178,11 @@ Q3DSEngine::Q3DSEngine() initResources(); registerQmlTypes(); + if (isAsyncLoadingEnabled()) { + m_slideResourceMutex = new QMutex; + m_asyncLoadMutex = new QMutex; + } + QMutexLocker locker(&q3ds_msg_mutex); q3ds_msg_engine = this; // Install the message handler once, it is then set for ever. Engines come @@ -903,15 +914,18 @@ void Q3DSEngine::beginAsyncLoad(Q3DSSubPresentation &sp, SceneLoaderAsync *loade qCDebug(lcScene, "Subpresentation %s loaded in %lld ms", qPrintable(loader->pres->subPres.id), timer.elapsed()); }); - QMutexLocker locker(&m_asyncLoadLock); + QMutexLocker locker(m_asyncLoadMutex); m_asyncSceneLoaders.push_back(loader); } void Q3DSEngine::finishAsyncLoadForSubpresentation(const QString &name) { + if (!m_asyncLoadMutex) + return; + QVector<SceneLoaderAsync *> loaders; { - QMutexLocker locker(&m_asyncLoadLock); + QMutexLocker locker(m_asyncLoadMutex); loaders = m_asyncSceneLoaders; } for (auto &item : qAsConst(loaders)) { @@ -926,10 +940,13 @@ void Q3DSEngine::finishAsyncLoadForSubpresentation(const QString &name) void Q3DSEngine::finishAsyncLoad(bool wait) { + if (!m_asyncLoadMutex) + return; + QThread *currentThread = QThread::currentThread(); QVector<SceneLoaderAsync *> loaders; { - QMutexLocker locker(&m_asyncLoadLock); + QMutexLocker locker(m_asyncLoadMutex); loaders = m_asyncSceneLoaders; } if (wait) { @@ -962,13 +979,18 @@ void Q3DSEngine::finishAsyncLoad(bool wait) void Q3DSEngine::loadSlideResources(Q3DSSlide *slide, Q3DSUipPresentation *presentation) { - QSet<QUrl> createSet; - { - QMutexLocker locker(&m_slideResourceMutex); + if (m_slideResourceMutex) { + QSet<QUrl> createSet; + { + QMutexLocker locker(m_slideResourceMutex); + m_resourceReferenceCounter.handleLoadSlide(slide, presentation); + createSet = m_resourceReferenceCounter.createSet; + } + Q3DSImageManager::instance().beginImageLoad(createSet); + } else { m_resourceReferenceCounter.handleLoadSlide(slide, presentation); - createSet = m_resourceReferenceCounter.createSet; + Q3DSImageManager::instance().beginImageLoad(m_resourceReferenceCounter.createSet); } - Q3DSImageManager::instance().beginImageLoad(createSet); } void Q3DSEngine::unloadSlideResources(Q3DSSlide *slide, Q3DSUipPresentation *presentation) diff --git a/src/runtime/q3dsengine_p.h b/src/runtime/q3dsengine_p.h index ae76bb4..1d3f23d 100644 --- a/src/runtime/q3dsengine_p.h +++ b/src/runtime/q3dsengine_p.h @@ -472,8 +472,8 @@ private: QVector<SceneLoaderAsync *> m_asyncSceneLoaders; SlideResourceCounter m_resourceReferenceCounter; - QMutex m_slideResourceMutex; - QMutex m_asyncLoadLock; + QMutex *m_slideResourceMutex = nullptr; + QMutex *m_asyncLoadMutex= nullptr; }; Q_DECLARE_OPERATORS_FOR_FLAGS(Q3DSEngine::Flags) |