Use QBasicAtomicInt load() and store() instead of implicit casting
authorBradley T. Hughes <bradley.hughes@nokia.com>
Mon, 10 Oct 2011 14:27:10 +0000 (16:27 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 10 Oct 2011 19:21:50 +0000 (21:21 +0200)
The implicit casts will be unavailable in the near future.

This is a follow up to commit 7f8472af8c03296be9e9ce50d8e9b3089eedf2f1,
which didn't catch all usages of the implicit cast and assignment
operator.

Change-Id: If05c343e2851b41e4a351c56328c4406c688fa0d
Reviewed-on: http://codereview.qt-project.org/6351
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>

src/declarative/qml/ftw/qdeclarativerefcount_p.h
src/declarative/qml/qdeclarativetypeloader.cpp
src/declarative/util/qdeclarativexmllistmodel.cpp
src/qtquick1/util/qdeclarativexmllistmodel.cpp

index 8ae9618..b9b32b2 100644 (file)
@@ -109,18 +109,18 @@ QDeclarativeRefCount::QDeclarativeRefCount()
 
 QDeclarativeRefCount::~QDeclarativeRefCount() 
 {
-    Q_ASSERT(refCount == 0);
+    Q_ASSERT(refCount.load() == 0);
 }
 
 void QDeclarativeRefCount::addref() 
 { 
-    Q_ASSERT(refCount > 0); 
+    Q_ASSERT(refCount.load() > 0);
     refCount.ref(); 
 }
 
 void QDeclarativeRefCount::release() 
 { 
-    Q_ASSERT(refCount > 0); 
+    Q_ASSERT(refCount.load() > 0);
     if (!refCount.deref()) 
         destroy(); 
 }
index ebda11f..982692d 100644 (file)
@@ -692,13 +692,13 @@ QDeclarativeDataBlob::ThreadData::ThreadData()
 
 QDeclarativeDataBlob::Status QDeclarativeDataBlob::ThreadData::status() const
 {
-    return QDeclarativeDataBlob::Status((_p & TD_STATUS_MASK) >> TD_STATUS_SHIFT);
+    return QDeclarativeDataBlob::Status((_p.load() & TD_STATUS_MASK) >> TD_STATUS_SHIFT);
 }
 
 void QDeclarativeDataBlob::ThreadData::setStatus(QDeclarativeDataBlob::Status status)
 {
     while (true) {
-        int d = _p;
+        int d = _p.load();
         int nd = (d & ~TD_STATUS_MASK) | ((status << TD_STATUS_SHIFT) & TD_STATUS_MASK);
         if (d == nd || _p.testAndSetOrdered(d, nd)) return;
     }
@@ -706,13 +706,13 @@ void QDeclarativeDataBlob::ThreadData::setStatus(QDeclarativeDataBlob::Status st
 
 bool QDeclarativeDataBlob::ThreadData::isAsync() const
 {
-    return _p & TD_ASYNC_MASK;
+    return _p.load() & TD_ASYNC_MASK;
 }
 
 void QDeclarativeDataBlob::ThreadData::setIsAsync(bool v)
 {
     while (true) {
-        int d = _p;
+        int d = _p.load();
         int nd = (d & ~TD_ASYNC_MASK) | (v?TD_ASYNC_MASK:0);
         if (d == nd || _p.testAndSetOrdered(d, nd)) return;
     }
@@ -720,13 +720,13 @@ void QDeclarativeDataBlob::ThreadData::setIsAsync(bool v)
 
 quint8 QDeclarativeDataBlob::ThreadData::progress() const
 {
-    return quint8((_p & TD_PROGRESS_MASK) >> TD_PROGRESS_SHIFT);
+    return quint8((_p.load() & TD_PROGRESS_MASK) >> TD_PROGRESS_SHIFT);
 }
 
 void QDeclarativeDataBlob::ThreadData::setProgress(quint8 v)
 {
     while (true) {
-        int d = _p;
+        int d = _p.load();
         int nd = (d & ~TD_PROGRESS_MASK) | ((v << TD_PROGRESS_SHIFT) & TD_PROGRESS_MASK);
         if (d == nd || _p.testAndSetOrdered(d, nd)) return;
     }
index 82b7e7d..2dd7b57 100644 (file)
@@ -253,12 +253,12 @@ int QDeclarativeXmlQueryEngine::doQuery(QString query, QString namespaces, QByte
     {
         QMutexLocker m1(&m_mutex);
         m_queryIds.ref();
-        if (m_queryIds <= 0)
-            m_queryIds = 1;
+        if (m_queryIds.load() <= 0)
+            m_queryIds.store(1);
     }
 
     XmlQueryJob job;
-    job.queryId = m_queryIds;
+    job.queryId = m_queryIds.load();
     job.data = data;
     job.query = QLatin1String("doc($src)") + query;
     job.namespaces = namespaces;
index 2450534..d831590 100644 (file)
@@ -179,12 +179,12 @@ public:
         {
             QMutexLocker m1(&m_mutex);
             m_queryIds.ref();
-            if (m_queryIds <= 0)
-                m_queryIds = 1;
+            if (m_queryIds.load() <= 0)
+                m_queryIds.store(1);
         }
 
         XmlQueryJob job;
-        job.queryId = m_queryIds;
+        job.queryId = m_queryIds.load();
         job.data = data;
         job.query = QLatin1String("doc($src)") + query;
         job.namespaces = namespaces;
@@ -203,7 +203,7 @@ public:
 
         {
             QMutexLocker ml(&m_mutex);
-            m_jobs.insert(m_queryIds, job);
+            m_jobs.insert(m_queryIds.load(), job);
         }
 
         QMetaObject::invokeMethod(this, "processQuery", Qt::QueuedConnection, Q_ARG(int, job.queryId));