diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2014-11-20 09:07:52 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-12-29 14:39:22 +0100 |
commit | efc3cc717ac1a62965465e909cc99acef627cdb1 (patch) | |
tree | 9d181ca8e9e299fa99b9b7598bfb83bc53056dde /src/qml/qml/qqmlengine_p.h | |
parent | 65953304a2775e69c7edd46b780aa39f769d32ac (diff) |
Make QQmlPropertyCache available in QJSEngine
The QQmlEngine has two containers for property caches, one for QML types and
one for all-purpose meta-objects. The latter is rather useful and now being
moved to QJSEngine to be available there.
Change-Id: Ieab65c400b8a2e410e5f9eee6d603162dbb864d9
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlengine_p.h')
-rw-r--r-- | src/qml/qml/qqmlengine_p.h | 108 |
1 files changed, 1 insertions, 107 deletions
diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h index a1935b854b..de2a2d3e1d 100644 --- a/src/qml/qml/qqmlengine_p.h +++ b/src/qml/qml/qqmlengine_p.h @@ -208,9 +208,8 @@ public: inline static void deleteInEngineThread(QQmlEngine *, T *); // These methods may be called from the loader thread - inline QQmlPropertyCache *cache(QObject *obj); - inline QQmlPropertyCache *cache(const QMetaObject *); inline QQmlPropertyCache *cache(QQmlType *, int, QQmlError &error); + using QJSEnginePrivate::cache; // These methods may be called from the loader thread bool isQObject(int); @@ -260,40 +259,13 @@ public: static bool qml_debugging_enabled; mutable QMutex networkAccessManagerMutex; - mutable QMutex mutex; private: - // Locker locks the QQmlEnginePrivate data structures for read and write, if necessary. - // Currently, locking is only necessary if the threaded loader is running concurrently. If it is - // either idle, or is running with the main thread blocked, no locking is necessary. This way - // we only pay for locking when we have to. - // Consequently, this class should only be used to protect simple accesses or modifications of the - // QQmlEnginePrivate structures or operations that can be guaranteed not to start activity - // on the loader thread. - // The Locker API is identical to QMutexLocker. Locker reuses the QQmlEnginePrivate::mutex - // QMutex instance and multiple Lockers are recursive in the same thread. - class Locker - { - public: - inline Locker(const QQmlEngine *); - inline Locker(const QQmlEnginePrivate *); - inline ~Locker(); - - inline void unlock(); - inline void relock(); - - private: - const QQmlEnginePrivate *m_ep; - quint32 m_locked:1; - }; - // Must be called locked - QQmlPropertyCache *createCache(const QMetaObject *); QQmlPropertyCache *createCache(QQmlType *, int, QQmlError &error); // These members must be protected by a QQmlEnginePrivate::Locker as they are required by // the threaded loader. Only access them through their respective accessor methods. - QHash<const QMetaObject *, QQmlPropertyCache *> propertyCache; QHash<QPair<QQmlType *, int>, QQmlPropertyCache *> typePropertyCache; QHash<int, int> m_qmlLists; QHash<int, QQmlCompiledData *> m_compositeTypes; @@ -306,38 +278,6 @@ private: void doDeleteInEngineThread(); }; -QQmlEnginePrivate::Locker::Locker(const QQmlEngine *e) -: m_ep(QQmlEnginePrivate::get(e)) -{ - relock(); -} - -QQmlEnginePrivate::Locker::Locker(const QQmlEnginePrivate *e) -: m_ep(e), m_locked(false) -{ - relock(); -} - -QQmlEnginePrivate::Locker::~Locker() -{ - unlock(); -} - -void QQmlEnginePrivate::Locker::unlock() -{ - if (m_locked) { - m_ep->mutex.unlock(); - m_locked = false; - } -} - -void QQmlEnginePrivate::Locker::relock() -{ - Q_ASSERT(!m_locked); - m_ep->mutex.lock(); - m_locked = true; -} - /*! Returns true if the calling thread is the QQmlEngine thread. */ @@ -402,52 +342,6 @@ void QQmlEnginePrivate::deleteInEngineThread(QQmlEngine *engine, T *value) } /*! -Returns a QQmlPropertyCache for \a obj if one is available. - -If \a obj is null, being deleted or contains a dynamic meta object 0 -is returned. - -The returned cache is not referenced, so if it is to be stored, call addref(). - -XXX thread There is a potential future race condition in this and all the cache() -functions. As the QQmlPropertyCache is returned unreferenced, when called -from the loader thread, it is possible that the cache will have been dereferenced -and deleted before the loader thread has a chance to use or reference it. This -can't currently happen as the cache holds a reference to the -QQmlPropertyCache until the QQmlEngine is destroyed. -*/ -QQmlPropertyCache *QQmlEnginePrivate::cache(QObject *obj) -{ - if (!obj || QObjectPrivate::get(obj)->metaObject || QObjectPrivate::get(obj)->wasDeleted) - return 0; - - Locker locker(this); - const QMetaObject *mo = obj->metaObject(); - QQmlPropertyCache *rv = propertyCache.value(mo); - if (!rv) rv = createCache(mo); - return rv; -} - -/*! -Returns a QQmlPropertyCache for \a metaObject. - -As the cache is persisted for the life of the engine, \a metaObject must be -a static "compile time" meta-object, or a meta-object that is otherwise known to -exist for the lifetime of the QQmlEngine. - -The returned cache is not referenced, so if it is to be stored, call addref(). -*/ -QQmlPropertyCache *QQmlEnginePrivate::cache(const QMetaObject *metaObject) -{ - Q_ASSERT(metaObject); - - Locker locker(this); - QQmlPropertyCache *rv = propertyCache.value(metaObject); - if (!rv) rv = createCache(metaObject); - return rv; -} - -/*! Returns a QQmlPropertyCache for \a type with \a minorVersion. The returned cache is not referenced, so if it is to be stored, call addref(). |