diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-06-09 14:56:00 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-06-09 16:49:41 +0200 |
commit | b55c3d4f6cc14416c64a7e796abe3d9fd996fc94 (patch) | |
tree | b4ac469cdb40ad0aeda2a4bb276bb92858c92d40 /src | |
parent | 9752ad5af7c7ae188250ab5b8b65c74f70d57b41 (diff) |
QQmlTypePrivate: do not abuse volatile for atomic
Instead of using volatile, use proper atomics for thread safe access.
Moreover, we don't gain anything by using bitfields here, as we have
space for 4 bools due to alignment reasons anyway. Therefore using bools
does not create any overhead.
Change-Id: I390acd935656efcb20265ddb67fa0059f3f18118
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmltype.cpp | 14 | ||||
-rw-r--r-- | src/qml/qml/qqmltype_p_p.h | 10 |
3 files changed, 14 insertions, 12 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 24a8bcfed3..5e66758b43 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -91,7 +91,7 @@ static QQmlTypePrivate *createQQmlType(QQmlMetaTypeData *data, d->iid = type.iid; d->typeId = type.typeId; d->listId = type.listId; - d->isSetup = true; + d->isSetup.storeRelease(true); d->module = QString::fromUtf8(type.uri); d->version = type.version; data->registerType(d); diff --git a/src/qml/qml/qqmltype.cpp b/src/qml/qml/qqmltype.cpp index 0b21cc22ee..ffb1e0ac4c 100644 --- a/src/qml/qml/qqmltype.cpp +++ b/src/qml/qml/qqmltype.cpp @@ -207,11 +207,11 @@ static bool isPropertyRevisioned(const QMetaObject *mo, int index) void QQmlTypePrivate::init() const { - if (isSetup) + if (isSetup.loadAcquire()) return; QMutexLocker lock(QQmlMetaType::typeRegistrationLock()); - if (isSetup) + if (isSetup.loadAcquire()) return; const QMetaObject *mo = baseMetaObject; @@ -265,17 +265,17 @@ void QQmlTypePrivate::init() const } } - isSetup = true; + isSetup.storeRelease(true); lock.unlock(); } void QQmlTypePrivate::initEnums(QQmlEnginePrivate *engine) const { - const QQmlPropertyCache *cache = (!isEnumFromCacheSetup && isComposite()) + const QQmlPropertyCache *cache = (!isEnumFromCacheSetup.loadAcquire() && isComposite()) ? compositePropertyCache(engine) : nullptr; - const QMetaObject *metaObject = !isEnumFromBaseSetup + const QMetaObject *metaObject = !isEnumFromBaseSetup.loadAcquire() ? baseMetaObject // beware: It could be a singleton type without metaobject : nullptr; @@ -288,12 +288,12 @@ void QQmlTypePrivate::initEnums(QQmlEnginePrivate *engine) const if (cache) { insertEnumsFromPropertyCache(cache); - isEnumFromCacheSetup = true; + isEnumFromCacheSetup.storeRelease(true); } if (metaObject) { insertEnums(metaObject); - isEnumFromBaseSetup = true; + isEnumFromBaseSetup.storeRelease(true); } } diff --git a/src/qml/qml/qqmltype_p_p.h b/src/qml/qml/qqmltype_p_p.h index c94ac8c130..8cce5b7910 100644 --- a/src/qml/qml/qqmltype_p_p.h +++ b/src/qml/qml/qqmltype_p_p.h @@ -58,6 +58,8 @@ #include <private/qqmlpropertycache_p.h> #include <private/qqmlmetatype_p.h> +#include <QAtomicInteger> + QT_BEGIN_NAMESPACE class QQmlTypePrivate : public QQmlRefCount @@ -166,10 +168,10 @@ public: const QMetaObject *baseMetaObject; int index; - mutable volatile bool isSetup:1; - mutable volatile bool isEnumFromCacheSetup:1; - mutable volatile bool isEnumFromBaseSetup:1; - mutable bool haveSuperType:1; + mutable QAtomicInteger<bool> isSetup; + mutable QAtomicInteger<bool> isEnumFromCacheSetup; + mutable QAtomicInteger<bool> isEnumFromBaseSetup; + mutable bool haveSuperType; mutable QList<QQmlProxyMetaObject::ProxyData> metaObjects; mutable QStringHash<int> enums; mutable QStringHash<int> scopedEnumIndex; // maps from enum name to index in scopedEnums |