diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-03-15 17:15:41 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-03-16 09:04:29 +0000 |
commit | d7b361bc33992ed61310b709df476cc4fa9f67e5 (patch) | |
tree | a5aff750947862fd6e5cbc1eb6c677453caba1ae /src/qml/qml | |
parent | 3339bf866a68ba129e88fd7d27a2abbea0d1c6ba (diff) |
Reduce the overhead of type loader locking
Allow pulling the shared mutex out of the QQmlThread for the type loader
so that the lock and unlock calls can be inlined. We do a lot more of
those now.
Task-number: QTBUG-41465
Change-Id: I42f3d17feb08863f51b003b061d89f49c5a6d574
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/ftw/qqmlthread.cpp | 6 | ||||
-rw-r--r-- | src/qml/qml/ftw/qqmlthread_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 16 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader_p.h | 5 |
4 files changed, 15 insertions, 14 deletions
diff --git a/src/qml/qml/ftw/qqmlthread.cpp b/src/qml/qml/ftw/qqmlthread.cpp index 78b477b472..96313d7627 100644 --- a/src/qml/qml/ftw/qqmlthread.cpp +++ b/src/qml/qml/ftw/qqmlthread.cpp @@ -57,6 +57,7 @@ public: void run() override; + inline QMutex &mutex() { return _mutex; } inline void lock() { _mutex.lock(); } inline void unlock() { _mutex.unlock(); } inline void wait() { _wait.wait(&_mutex); } @@ -263,6 +264,11 @@ bool QQmlThread::isShutdown() const return d->m_shutdown; } +QMutex &QQmlThread::mutex() +{ + return d->mutex(); +} + void QQmlThread::lock() { d->lock(); diff --git a/src/qml/qml/ftw/qqmlthread_p.h b/src/qml/qml/ftw/qqmlthread_p.h index 0ed12a2972..b5c580fe8b 100644 --- a/src/qml/qml/ftw/qqmlthread_p.h +++ b/src/qml/qml/ftw/qqmlthread_p.h @@ -59,6 +59,7 @@ QT_BEGIN_NAMESPACE class QThread; +class QMutex; class QQmlThreadPrivate; class QQmlThread @@ -71,6 +72,7 @@ public: void shutdown(); bool isShutdown() const; + QMutex &mutex(); void lock(); void unlock(); void wakeOne(); diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 61208d1c4a..5b954605e0 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -983,16 +983,6 @@ void QQmlTypeLoader::setProfiler(QQmlProfiler *profiler) } #endif -void QQmlTypeLoader::lock() -{ - m_thread->lock(); -} - -void QQmlTypeLoader::unlock() -{ - m_thread->unlock(); -} - struct PlainLoader { void loadThread(QQmlTypeLoader *loader, QQmlDataBlob *blob) const { @@ -1632,8 +1622,10 @@ bool QQmlTypeLoaderQmldirContent::designerSupported() const Constructs a new type loader that uses the given \a engine. */ QQmlTypeLoader::QQmlTypeLoader(QQmlEngine *engine) - : m_engine(engine), m_thread(new QQmlTypeLoaderThread(this)), - m_typeCacheTrimThreshold(TYPELOADER_MINIMUM_TRIM_THRESHOLD) + : m_engine(engine) + , m_thread(new QQmlTypeLoaderThread(this)) + , m_mutex(m_thread->mutex()) + , m_typeCacheTrimThreshold(TYPELOADER_MINIMUM_TRIM_THRESHOLD) { } diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index 713f707387..df79d13f1c 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -313,8 +313,8 @@ public: bool isTypeLoaded(const QUrl &url) const; bool isScriptLoaded(const QUrl &url) const; - void lock(); - void unlock(); + void lock() { m_mutex.lock(); } + void unlock() { m_mutex.unlock(); } void load(QQmlDataBlob *, Mode = PreferSynchronous); void loadWithStaticData(QQmlDataBlob *, const QByteArray &, Mode = PreferSynchronous); @@ -381,6 +381,7 @@ private: QQmlEngine *m_engine; QQmlTypeLoaderThread *m_thread; + QMutex &m_mutex; #if QT_CONFIG(qml_debug) QScopedPointer<QQmlProfiler> m_profiler; |