Replace implicit QAtomic* casts with explicit load()/store()
authorBradley T. Hughes <bradley.hughes@nokia.com>
Thu, 29 Sep 2011 09:50:08 +0000 (11:50 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 27 Oct 2011 16:57:38 +0000 (18:57 +0200)
Change-Id: Ia7ef1a8e01001f203e409c710c977d6f4686342e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
49 files changed:
src/corelib/concurrent/qfutureinterface.cpp
src/corelib/concurrent/qfuturewatcher.cpp
src/corelib/concurrent/qtconcurrentiteratekernel.h
src/corelib/concurrent/qtconcurrentthreadengine.cpp
src/corelib/io/qprocess_p.h
src/corelib/io/qurl.cpp
src/corelib/kernel/qabstractitemmodel.cpp
src/corelib/kernel/qobject.cpp
src/corelib/kernel/qvariant.cpp
src/corelib/kernel/qvariant.h
src/corelib/thread/qatomic.h
src/corelib/thread/qmutex.cpp
src/corelib/thread/qmutex_p.h
src/corelib/thread/qmutexpool.cpp
src/corelib/thread/qmutexpool_p.h
src/corelib/thread/qthread.cpp
src/corelib/tools/qregexp.cpp
src/corelib/tools/qsharedpointer.cpp
src/gui/image/qimage.cpp
src/gui/image/qpicture.cpp
src/gui/image/qpixmap.cpp
src/gui/kernel/qevent.cpp
src/gui/kernel/qkeysequence.cpp
src/gui/kernel/qopenglcontext.cpp
src/gui/kernel/qpalette.cpp
src/gui/kernel/qsurfaceformat.cpp
src/gui/opengl/qopenglframebufferobject.cpp
src/gui/painting/qbrush.cpp
src/gui/painting/qbrush.h
src/gui/painting/qpainterpath.h
src/gui/painting/qpainterpath_p.h
src/gui/painting/qpen.cpp
src/gui/text/qfont.cpp
src/gui/text/qfontengine.cpp
src/gui/text/qglyphrun.cpp
src/gui/text/qplatformfontdatabase_qpa.cpp
src/gui/text/qrawfont.cpp
src/gui/text/qrawfont_p.h
src/gui/text/qstatictext.cpp
src/gui/text/qtextengine.cpp
src/network/bearer/qbearerengine.cpp
src/network/kernel/qnetworkproxy.cpp
src/opengl/qgl.cpp
src/opengl/qglframebufferobject.cpp
src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
src/sql/kernel/qsqldatabase.cpp
src/sql/kernel/qsqlquery.cpp
src/widgets/kernel/qicon.cpp
src/xml/dom/qdom.cpp

index 74c3af0..f54b335 100644 (file)
@@ -416,7 +416,7 @@ QFutureInterfaceBase &QFutureInterfaceBase::operator=(const QFutureInterfaceBase
 
 bool QFutureInterfaceBase::referenceCountIsOne() const
 {
-    return d->refCount == 1;
+    return d->refCount.load() == 1;
 }
 
 QFutureInterfaceBasePrivate::QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState)
index 5c5d65d..c9a16a8 100644 (file)
@@ -464,7 +464,7 @@ void QFutureWatcherBasePrivate::sendCallOutEvent(QFutureCallOutEvent *event)
 
             emit q->resultsReadyAt(beginIndex, endIndex);
 
-            if (int(resultAtConnected) <= 0)
+            if (resultAtConnected.load() <= 0)
                 break;
 
             for (int i = beginIndex; i < endIndex; ++i)
index c6fcb97..49c053c 100644 (file)
@@ -214,9 +214,9 @@ public:
     bool shouldStartThread()
     {
         if (forIteration)
-            return (currentIndex < iterationCount) && !this->shouldThrottleThread();
+            return (currentIndex.load() < iterationCount) && !this->shouldThrottleThread();
         else // whileIteration
-            return (iteratorThreads == 0);
+            return (iteratorThreads.load() == 0);
     }
 
     ThreadFunctionResult threadFunction()
@@ -238,7 +238,7 @@ public:
 
             const int currentBlockSize = blockSizeManager.blockSize();
 
-            if (currentIndex >= iterationCount)
+            if (currentIndex.load() >= iterationCount)
                 break;
 
             // Atomically reserve a block of iterationCount for this thread.
@@ -269,7 +269,7 @@ public:
             // Report progress if progress reporting enabled.
             if (progressReportingEnabled) {
                 completed.fetchAndAddAcquire(finalBlockSize);
-                this->setProgressValue(this->completed);
+                this->setProgressValue(this->completed.load());
             }
 
             if (this->shouldThrottleThread())
index bb9b080..71a4716 100644 (file)
@@ -53,7 +53,7 @@ ThreadEngineBarrier::ThreadEngineBarrier()
 void ThreadEngineBarrier::acquire()
 {
     forever {
-        int localCount = int(count);
+        int localCount = count.load();
         if (localCount < 0) {
             if (count.testAndSetOrdered(localCount, localCount -1))
                 return;
@@ -67,7 +67,7 @@ void ThreadEngineBarrier::acquire()
 int ThreadEngineBarrier::release()
 {
     forever {
-        int localCount = int(count);
+        int localCount = count.load();
         if (localCount == -1) {
             if (count.testAndSetOrdered(-1, 0)) {
                 semaphore.release();
@@ -87,7 +87,7 @@ int ThreadEngineBarrier::release()
 void ThreadEngineBarrier::wait()
 {
     forever {
-        int localCount = int(count);
+        int localCount = count.load();
         if (localCount == 0)
             return;
 
@@ -101,7 +101,7 @@ void ThreadEngineBarrier::wait()
 
 int ThreadEngineBarrier::currentCount()
 {
-    return int(count);
+    return count.load();
 }
 
 // releases a thread, unless this is the last thread.
@@ -109,7 +109,7 @@ int ThreadEngineBarrier::currentCount()
 bool ThreadEngineBarrier::releaseUnlessLast()
 {
     forever {
-        int localCount = int(count);
+        int localCount = count.load();
         if (qAbs(localCount) == 1) {
             return false;
         } else if (localCount < 0) {
index 9adb331..5bebff0 100644 (file)
@@ -184,7 +184,7 @@ public:
 
 template<> Q_INLINE_TEMPLATE void QSharedDataPointer<QProcessEnvironmentPrivate>::detach()
 {
-    if (d && d->ref == 1)
+    if (d && d->ref.load() == 1)
         return;
     QProcessEnvironmentPrivate *x = (d ? new QProcessEnvironmentPrivate(*d)
                                      : new QProcessEnvironmentPrivate);
index 6dca036..b960528 100644 (file)
@@ -6102,7 +6102,7 @@ void QUrl::detach()
 */
 bool QUrl::isDetached() const
 {
-    return !d || d->ref == 1;
+    return !d || d->ref.load() == 1;
 }
 
 
index b7ac6aa..bda25c3 100644 (file)
@@ -74,7 +74,7 @@ QPersistentModelIndexData *QPersistentModelIndexData::create(const QModelIndex &
 void QPersistentModelIndexData::destroy(QPersistentModelIndexData *data)
 {
     Q_ASSERT(data);
-    Q_ASSERT(data->ref == 0);
+    Q_ASSERT(data->ref.load() == 0);
     QAbstractItemModel *model = const_cast<QAbstractItemModel *>(data->model);
     // a valid persistent model index with a null model pointer can only happen if the model was destroyed
     if (model) {
index 4c969c8..555bfa6 100644 (file)
@@ -807,19 +807,19 @@ QObject::~QObject()
         QObjectPrivate::clearGuards(this);
     }
 
-    if (d->sharedRefcount) {
-        if (d->sharedRefcount->strongref.load() > 0) {
+    QtSharedPointer::ExternalRefCountData *sharedRefcount = d->sharedRefcount.load();
+    if (sharedRefcount) {
+        if (sharedRefcount->strongref.load() > 0) {
             qWarning("QObject: shared QObject was deleted directly. The program is malformed and may crash.");
             // but continue deleting, it's too late to stop anyway
         }
 
         // indicate to all QWeakPointers that this QObject has now been deleted
-        d->sharedRefcount->strongref.store(0);
-        if (!d->sharedRefcount->weakref.deref())
-            delete d->sharedRefcount;
+        sharedRefcount->strongref.store(0);
+        if (!sharedRefcount->weakref.deref())
+            delete sharedRefcount;
     }
 
-
     if (d->isSignalConnected(0)) {
         QT_TRY {
             emit destroyed(this);
index 76957f1..470be1c 100644 (file)
@@ -1823,7 +1823,7 @@ QVariant& QVariant::operator=(const QVariant &variant)
 
 void QVariant::detach()
 {
-    if (!d.is_shared || d.data.shared->ref == 1)
+    if (!d.is_shared || d.data.shared->ref.load() == 1)
         return;
 
     Private dd;
index e77fc90..61dc48a 100644 (file)
@@ -448,7 +448,7 @@ Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant::Type p);
 #endif
 
 inline bool QVariant::isDetached() const
-{ return !d.is_shared || d.data.shared->ref == 1; }
+{ return !d.is_shared || d.data.shared->ref.load() == 1; }
 
 
 #ifdef qdoc
index 6fe4d65..0b72ce9 100644 (file)
@@ -259,7 +259,7 @@ inline void qAtomicAssign(T *&d, T *x)
 template <typename T>
 inline void qAtomicDetach(T *&d)
 {
-    if (d->ref == 1)
+    if (d->ref.load() == 1)
         return;
     T *x = d;
     d = new T(*d);
index e2da0ad..959d1f9 100644 (file)
@@ -154,7 +154,7 @@ QMutex::~QMutex()
         delete static_cast<QRecursiveMutexPrivate *>(d.load());
     else if (d.load()) {
 #ifndef Q_OS_LINUX
-        if (d.load()->possiblyUnlocked && tryLock()) { unlock(); return; }
+        if (d.load()->possiblyUnlocked.load() && tryLock()) { unlock(); return; }
 #endif
         qWarning("QMutex: destroying locked mutex");
     }
@@ -361,7 +361,7 @@ bool QBasicMutex::lockInternal(int timeout)
              return static_cast<QRecursiveMutexPrivate *>(d)->lock(timeout);
         }
 
-        if (timeout == 0 && !d->possiblyUnlocked)
+        if (timeout == 0 && !d->possiblyUnlocked.load())
             return false;
 
         if (!d->ref())
@@ -375,7 +375,7 @@ bool QBasicMutex::lockInternal(int timeout)
 
         int old_waiters;
         do {
-            old_waiters = d->waiters;
+            old_waiters = d->waiters.load();
             if (old_waiters == -QMutexPrivate::BigNumber) {
                 // we are unlocking, and the thread that unlocks is about to change d to 0
                 // we try to aquire the mutex by changing to dummyLocked()
@@ -407,7 +407,7 @@ bool QBasicMutex::lockInternal(int timeout)
         }
 
         if (d->wait(timeout)) {
-            if (d->possiblyUnlocked && d->possiblyUnlocked.testAndSetRelaxed(true, false))
+            if (d->possiblyUnlocked.load() && d->possiblyUnlocked.testAndSetRelaxed(true, false))
                 d->deref();
             d->derefWaiters(1);
             //we got the lock. (do not deref)
@@ -445,7 +445,7 @@ void QBasicMutex::unlockInternal()
     if (d->waiters.fetchAndAddRelease(-QMutexPrivate::BigNumber) == 0) {
         //there is no one waiting on this mutex anymore, set the mutex as unlocked (d = 0)
         if (this->d.testAndSetRelease(d, 0)) {
-            if (d->possiblyUnlocked && d->possiblyUnlocked.testAndSetRelaxed(true, false))
+            if (d->possiblyUnlocked.load() && d->possiblyUnlocked.testAndSetRelaxed(true, false))
                 d->deref();
         }
         d->derefWaiters(0);
@@ -479,10 +479,10 @@ QMutexPrivate *QMutexPrivate::allocate()
     int i = freelist()->next();
     QMutexPrivate *d = &(*freelist())[i];
     d->id = i;
-    Q_ASSERT(d->refCount == 0);
+    Q_ASSERT(d->refCount.load() == 0);
     Q_ASSERT(!d->recursive);
-    Q_ASSERT(!d->possiblyUnlocked);
-    Q_ASSERT(d->waiters == 0);
+    Q_ASSERT(!d->possiblyUnlocked.load());
+    Q_ASSERT(d->waiters.load() == 0);
     d->refCount = 1;
     return d;
 }
@@ -490,9 +490,9 @@ QMutexPrivate *QMutexPrivate::allocate()
 void QMutexPrivate::release()
 {
     Q_ASSERT(!recursive);
-    Q_ASSERT(refCount == 0);
-    Q_ASSERT(!possiblyUnlocked);
-    Q_ASSERT(waiters == 0);
+    Q_ASSERT(refCount.load() == 0);
+    Q_ASSERT(!possiblyUnlocked.load());
+    Q_ASSERT(waiters.load() == 0);
     freelist()->release(id);
 }
 
@@ -502,7 +502,7 @@ void QMutexPrivate::derefWaiters(int value)
     int old_waiters;
     int new_waiters;
     do {
-        old_waiters = waiters;
+        old_waiters = waiters.load();
         new_waiters = old_waiters;
         if (new_waiters < 0) {
             new_waiters += QMutexPrivate::BigNumber;
index 00f071e..00bda48 100644 (file)
@@ -79,21 +79,21 @@ public:
     int id;
 
     bool ref() {
-        Q_ASSERT(refCount >= 0);
+        Q_ASSERT(refCount.load() >= 0);
         int c;
         do {
-            c = refCount;
+            c = refCount.load();
             if (c == 0)
                 return false;
         } while (!refCount.testAndSetRelaxed(c, c + 1));
-        Q_ASSERT(refCount >= 0);
+        Q_ASSERT(refCount.load() >= 0);
         return true;
     }
     void deref() {
-        Q_ASSERT(refCount >=0);
+        Q_ASSERT(refCount.load() >= 0);
         if (!refCount.deref())
             release();
-        Q_ASSERT(refCount >=0);
+        Q_ASSERT(refCount.load() >= 0);
     }
     void release();
     static QMutexPrivate *allocate();
index 49fb46b..ef4e956 100644 (file)
@@ -99,7 +99,7 @@ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size)
     : mutexes(size), recursionMode(recursionMode)
 {
     for (int index = 0; index < mutexes.count(); ++index) {
-        mutexes[index] = 0;
+        mutexes[index].store(0);
     }
 }
 
@@ -109,10 +109,8 @@ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size)
 */
 QMutexPool::~QMutexPool()
 {
-    for (int index = 0; index < mutexes.count(); ++index) {
-        delete mutexes[index];
-        mutexes[index] = 0;
-    }
+    for (int index = 0; index < mutexes.count(); ++index)
+        delete mutexes[index].load();
 }
 
 /*!
@@ -136,9 +134,9 @@ QMutex *QMutexPool::createMutex(int index)
 {
     // mutex not created, create one
     QMutex *newMutex = new QMutex(recursionMode);
-    if (!mutexes[index].testAndSetOrdered(0, newMutex))
+    if (!mutexes[index].testAndSetRelease(0, newMutex))
         delete newMutex;
-    return mutexes[index];
+    return mutexes[index].load();
 }
 
 /*!
index fa9a734..20449c2 100644 (file)
@@ -69,7 +69,7 @@ public:
 
     inline QMutex *get(const void *address) {
         int index = uint(quintptr(address)) % mutexes.count();
-        QMutex *m = mutexes[index];
+        QMutex *m = mutexes[index].load();
         if (m)
             return m;
         else
index 40cb258..31332cd 100644 (file)
@@ -85,7 +85,7 @@ QThreadData::QThreadData(int initialRefCount)
 
 QThreadData::~QThreadData()
 {
-    Q_ASSERT(_ref == 0);
+    Q_ASSERT(_ref.load() == 0);
 
     // In the odd case that Qt is running on a secondary thread, the main
     // thread instance will have been dereffed asunder because of the deref in
@@ -117,7 +117,7 @@ void QThreadData::ref()
 {
 #ifndef QT_NO_THREAD
     (void) _ref.ref();
-    Q_ASSERT(_ref != 0);
+    Q_ASSERT(_ref.load() != 0);
 #endif
 }
 
index 59a54f3..433939f 100644 (file)
@@ -1701,7 +1701,7 @@ void QRegExpEngine::dump() const
 
 void QRegExpEngine::setup()
 {
-    ref = 1;
+    ref.store(1);
 #ifndef QT_NO_REGEXP_CAPTURE
     f.resize(32);
     nf = 0;
index e9ae3cb..3406092 100644 (file)
@@ -1238,9 +1238,9 @@ void QtSharedPointer::ExternalRefCountData::setQObjectShared(const QObject *obj,
     Q_ASSERT(obj);
     QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject *>(obj));
 
-    if (d->sharedRefcount)
+    if (d->sharedRefcount.load() != 0)
         qFatal("QSharedPointer: pointer %p already has reference counting", obj);
-    d->sharedRefcount = this;
+    d->sharedRefcount.store(this);
 
     // QObject decreases the refcount too, so increase it up
     weakref.ref();
@@ -1252,7 +1252,7 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
     QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject *>(obj));
     Q_ASSERT_X(!d->wasDeleted, "QWeakPointer", "Detected QWeakPointer creation in a QObject being deleted");
 
-    ExternalRefCountData *that = d->sharedRefcount;
+    ExternalRefCountData *that = d->sharedRefcount.load();
     if (that) {
         that->weakref.ref();
         return that;
@@ -1264,9 +1264,10 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
     x->weakref.store(2);  // the QWeakPointer that called us plus the QObject itself
     if (!d->sharedRefcount.testAndSetRelease(0, x)) {
         delete x;
-        d->sharedRefcount->weakref.ref();
+        x = d->sharedRefcount.loadAcquire();
+        x->weakref.ref();
     }
-    return d->sharedRefcount.loadAcquire();
+    return x;
 }
 
 QT_END_NAMESPACE
index c74b715..a19b608 100644 (file)
@@ -1075,10 +1075,10 @@ QImage::operator QVariant() const
 void QImage::detach()
 {
     if (d) {
-        if (d->is_cached && d->ref == 1)
+        if (d->is_cached && d->ref.load() == 1)
             QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
 
-        if (d->ref != 1 || d->ro_data)
+        if (d->ref.load() != 1 || d->ro_data)
             *this = copy();
 
         if (d)
@@ -5289,7 +5289,7 @@ qint64 QImage::cacheKey() const
 
 bool QImage::isDetached() const
 {
-    return d && d->ref == 1;
+    return d && d->ref.load() == 1;
 }
 
 
@@ -5849,7 +5849,7 @@ bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFla
         return true;
 
     // No in-place conversion if we have to detach
-    if (ref > 1)
+    if (ref.load() > 1)
         return false;
 
     const InPlace_Image_Converter *const converterPtr = &inplace_converter_map[format][newFormat];
index 5d79f3f..dfc84c5 100644 (file)
@@ -226,7 +226,7 @@ void QPicture::detach()
 
 bool QPicture::isDetached() const
 {
-    return d_func()->ref == 1;
+    return d_func()->ref.load() == 1;
 }
 
 /*!
index c025aa9..2a2bd5d 100644 (file)
@@ -272,7 +272,7 @@ QPixmap::QPixmap(const char * const xpm[])
 
 QPixmap::~QPixmap()
 {
-    Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again
+    Q_ASSERT(!data || data->ref.load() >= 1); // Catch if ref-counting changes again
 }
 
 /*!
@@ -871,7 +871,7 @@ void QPixmap::fill(const QColor &color)
         return;
     }
 
-    if (data->ref == 1) {
+    if (data->ref.load() == 1) {
         // detach() will also remove this pixmap from caches, so
         // it has to be called even when ref == 1.
         detach();
@@ -1000,7 +1000,7 @@ QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap)
 
 bool QPixmap::isDetached() const
 {
-    return data && data->ref == 1;
+    return data && data->ref.load() == 1;
 }
 
 /*! \internal
@@ -1529,10 +1529,10 @@ void QPixmap::detach()
         rasterData->image.detach();
     }
 
-    if (data->is_cached && data->ref == 1)
+    if (data->is_cached && data->ref.load() == 1)
         QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(data.data());
 
-    if (data->ref != 1) {
+    if (data->ref.load() != 1) {
         *this = copy();
     }
     ++data->detach_no;
index c9e49ef..ba81e55 100644 (file)
@@ -3761,7 +3761,7 @@ qreal QTouchEvent::TouchPoint::pressure() const
 /*! \internal */
 void QTouchEvent::TouchPoint::setId(int id)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->id = id;
 }
@@ -3769,7 +3769,7 @@ void QTouchEvent::TouchPoint::setId(int id)
 /*! \internal */
 void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->state = state;
 }
@@ -3777,7 +3777,7 @@ void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
 /*! \internal */
 void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->rect.moveCenter(pos);
 }
@@ -3785,7 +3785,7 @@ void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->sceneRect.moveCenter(scenePos);
 }
@@ -3793,7 +3793,7 @@ void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->screenRect.moveCenter(screenPos);
 }
@@ -3801,7 +3801,7 @@ void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->normalizedPos = normalizedPos;
 }
@@ -3809,7 +3809,7 @@ void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->startPos = startPos;
 }
@@ -3817,7 +3817,7 @@ void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->startScenePos = startScenePos;
 }
@@ -3825,7 +3825,7 @@ void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->startScreenPos = startScreenPos;
 }
@@ -3833,7 +3833,7 @@ void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->startNormalizedPos = startNormalizedPos;
 }
@@ -3841,7 +3841,7 @@ void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormaliz
 /*! \internal */
 void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->lastPos = lastPos;
 }
@@ -3849,7 +3849,7 @@ void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->lastScenePos = lastScenePos;
 }
@@ -3857,7 +3857,7 @@ void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->lastScreenPos = lastScreenPos;
 }
@@ -3865,7 +3865,7 @@ void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
 /*! \internal */
 void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->lastNormalizedPos = lastNormalizedPos;
 }
@@ -3873,7 +3873,7 @@ void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalized
 /*! \internal */
 void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->rect = rect;
 }
@@ -3881,7 +3881,7 @@ void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
 /*! \internal */
 void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->sceneRect = sceneRect;
 }
@@ -3889,7 +3889,7 @@ void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect)
 /*! \internal */
 void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->screenRect = screenRect;
 }
@@ -3897,7 +3897,7 @@ void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect)
 /*! \internal */
 void QTouchEvent::TouchPoint::setPressure(qreal pressure)
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d = d->detach();
     d->pressure = pressure;
 }
index 2b42aaa..6ea502b 100644 (file)
@@ -1600,7 +1600,7 @@ bool QKeySequence::operator< (const QKeySequence &other) const
 */
 bool QKeySequence::isDetached() const
 {
-    return d->ref == 1;
+    return d->ref.load() == 1;
 }
 
 /*!
index b3ce224..2b2f13e 100644 (file)
@@ -544,7 +544,7 @@ QOpenGLMultiGroupSharedResource::~QOpenGLMultiGroupSharedResource()
         active.deref();
     }
 #ifndef QT_NO_DEBUG
-    if (active != 0) {
+    if (active.load() != 0) {
         qWarning("QtGui: Resources are still available at program shutdown.\n"
                  "          This is possibly caused by a leaked QOpenGLWidget, \n"
                  "          QOpenGLFramebufferObject or QOpenGLPixelBuffer.");
index f84a366..893cc5e 100644 (file)
@@ -753,7 +753,7 @@ bool QPalette::isBrushSet(ColorGroup cg, ColorRole cr) const
 */
 void QPalette::detach()
 {
-    if (d->ref != 1) {
+    if (d->ref.load() != 1) {
         QPalettePrivate *x = new QPalettePrivate;
         for(int grp = 0; grp < (int)NColorGroups; grp++) {
             for(int role = 0; role < (int)NColorRoles; role++)
index 6326033..33b04cc 100644 (file)
@@ -120,7 +120,7 @@ QSurfaceFormat::QSurfaceFormat(QSurfaceFormat::FormatOptions options) :
 */
 void QSurfaceFormat::detach()
 {
-    if (d->ref != 1) {
+    if (d->ref.load() != 1) {
         QSurfaceFormatPrivate *newd = new QSurfaceFormatPrivate(d);
         if (!d->ref.deref())
             delete d;
index f08cab8..5e7f527 100644 (file)
@@ -102,7 +102,7 @@ QT_BEGIN_NAMESPACE
 */
 void QOpenGLFramebufferObjectFormat::detach()
 {
-    if (d->ref != 1) {
+    if (d->ref.load() != 1) {
         QOpenGLFramebufferObjectFormatPrivate *newd
             = new QOpenGLFramebufferObjectFormatPrivate(d);
         if (!d->ref.deref())
index d1130a8..b4aa27d 100644 (file)
@@ -343,7 +343,7 @@ public:
     QBrushData *brush;
     QNullBrushData() : brush(new QBrushData)
     {
-        brush->ref = 1;
+        brush->ref.store(1);
         brush->style = Qt::BrushStyle(0);
         brush->color = Qt::black;
     }
@@ -402,7 +402,7 @@ void QBrush::init(const QColor &color, Qt::BrushStyle style)
         d.reset(new QBrushData);
         break;
     }
-    d->ref = 1;
+    d->ref.store(1);
     d->style = style;
     d->color = color;
 }
@@ -577,7 +577,7 @@ void QBrush::cleanUp(QBrushData *x)
 
 void QBrush::detach(Qt::BrushStyle newStyle)
 {
-    if (newStyle == d->style && d->ref == 1)
+    if (newStyle == d->style && d->ref.load() == 1)
         return;
 
     QScopedPointer<QBrushData> x;
@@ -605,7 +605,7 @@ void QBrush::detach(Qt::BrushStyle newStyle)
         x.reset(new QBrushData);
         break;
     }
-    x->ref = 1;
+    x->ref.store(1);
     x->style = newStyle;
     x->color = d->color;
     x->transform = d->transform;
index 80d9b43..daad47c 100644 (file)
@@ -174,7 +174,7 @@ inline Qt::BrushStyle QBrush::style() const { return d->style; }
 inline const QColor &QBrush::color() const { return d->color; }
 inline const QMatrix &QBrush::matrix() const { return d->transform.toAffine(); }
 inline QTransform QBrush::transform() const { return d->transform; }
-inline bool QBrush::isDetached() const { return d->ref == 1; }
+inline bool QBrush::isDetached() const { return d->ref.load() == 1; }
 
 
 /*******************************************************************************
index a2dfed6..9dc435f 100644 (file)
@@ -419,7 +419,7 @@ inline void QPainterPath::setElementPositionAt(int i, qreal x, qreal y)
 
 inline void QPainterPath::detach()
 {
-    if (d_ptr->ref != 1)
+    if (d_ptr->ref.load() != 1)
         detach_helper();
     setDirty(true);
 }
index 1b5da7e..93cc11c 100644 (file)
@@ -245,7 +245,7 @@ inline bool QPainterPathData::isClosed() const
 
 inline void QPainterPathData::close()
 {
-    Q_ASSERT(ref == 1);
+    Q_ASSERT(ref.load() == 1);
     require_moveTo = true;
     const QPainterPath::Element &first = elements.at(cStart);
     QPainterPath::Element &last = elements.last();
index a79e3a0..5a4582e 100644 (file)
@@ -230,10 +230,9 @@ typedef QPenPrivate QPenData;
 */
 inline QPenPrivate::QPenPrivate(const QBrush &_brush, qreal _width, Qt::PenStyle penStyle,
                                 Qt::PenCapStyle _capStyle, Qt::PenJoinStyle _joinStyle)
-    : dashOffset(0), miterLimit(2),
+    : ref(1), dashOffset(0), miterLimit(2),
       cosmetic(false)
 {
-    ref = 1;
     width = _width;
     brush = _brush;
     style = penStyle;
@@ -353,7 +352,7 @@ QPen::~QPen()
 
 void QPen::detach()
 {
-    if (d->ref == 1)
+    if (d->ref.load() == 1)
         return;
 
     QPenData *x = new QPenData(*static_cast<QPenData *>(d));
@@ -860,7 +859,7 @@ bool QPen::operator==(const QPen &p) const
 
 bool QPen::isDetached()
 {
-    return d->ref == 1;
+    return d->ref.load() == 1;
 }
 
 
index 7cd9fb1..23fe5ca 100644 (file)
@@ -667,7 +667,7 @@ QFont::QFont(QFontPrivate *data)
 */
 void QFont::detach()
 {
-    if (d->ref == 1) {
+    if (d->ref.load() == 1) {
         if (d->engineData)
             d->engineData->ref.deref();
         d->engineData = 0;
@@ -2631,11 +2631,11 @@ QFontCache::~QFontCache()
         EngineDataCache::ConstIterator it = engineDataCache.constBegin(),
                                  end = engineDataCache.constEnd();
         while (it != end) {
-            if (it.value()->ref == 0)
+            if (it.value()->ref.load() == 0)
                 delete it.value();
             else
                 FC_DEBUG("QFontCache::~QFontCache: engineData %p still has refcount %d",
-                         it.value(), int(it.value()->ref));
+                         it.value(), it.value()->ref.load());
             ++it;
         }
     }
@@ -2643,7 +2643,7 @@ QFontCache::~QFontCache()
                          end = engineCache.constEnd();
     while (it != end) {
         if (--it.value().data->cache_count == 0) {
-            if (it.value().data->ref == 0) {
+            if (it.value().data->ref.load() == 0) {
                 FC_DEBUG("QFontCache::~QFontCache: deleting engine %p key=(%d / %g %g %d %d %d)",
                          it.value().data, it.key().script, it.key().def.pointSize,
                          it.key().def.pixelSize, it.key().def.weight, it.key().def.style,
@@ -2652,7 +2652,7 @@ QFontCache::~QFontCache()
                 delete it.value().data;
             } else {
                 FC_DEBUG("QFontCache::~QFontCache: engine = %p still has refcount %d",
-                         it.value().data, int(it.value().data->ref));
+                         it.value().data, it.value().data->ref.load());
             }
         }
         ++it;
@@ -2678,7 +2678,7 @@ void QFontCache::clear()
 
     for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end();
          it != end; ++it) {
-        if (it->data->ref == 0) {
+        if (it->data->ref.load() == 0) {
             delete it->data;
             it->data = 0;
         }
@@ -2686,7 +2686,7 @@ void QFontCache::clear()
 
     for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end();
          it != end; ++it) {
-        if (it->data && it->data->ref == 0) {
+        if (it->data && it->data->ref.load() == 0) {
             delete it->data;
             it->data = 0;
         }
@@ -2727,7 +2727,7 @@ QFontEngine *QFontCache::findEngine(const Key &key)
     FC_DEBUG("QFontCache: found font engine\n"
              "  %p: timestamp %4u hits %3u ref %2d/%2d, type '%s'",
              it.value().data, it.value().timestamp, it.value().hits,
-             int(it.value().data->ref), it.value().data->cache_count,
+             it.value().data->ref.load(), it.value().data->cache_count,
              it.value().data->name());
 
     return it.value().data;
@@ -2782,7 +2782,6 @@ void QFontCache::decreaseCost(uint cost)
             cost, total_cost, max_cost);
 }
 
-
 void QFontCache::timerEvent(QTimerEvent *)
 {
     FC_DEBUG("QFontCache::timerEvent: performing cache maintenance (timestamp %u)",
@@ -2816,7 +2815,7 @@ void QFontCache::timerEvent(QTimerEvent *)
 
 #endif // QFONTCACHE_DEBUG
 
-            if (it.value()->ref != 0)
+            if (it.value()->ref.load() != 0)
                 in_use_cost += engine_data_cost;
         }
     }
@@ -2829,10 +2828,10 @@ void QFontCache::timerEvent(QTimerEvent *)
         for (; it != end; ++it) {
             FC_DEBUG("    %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes",
                      it.value().data, it.value().timestamp, it.value().hits,
-                     int(it.value().data->ref), it.value().data->cache_count,
+                     it.value().data->ref.load(), it.value().data->cache_count,
                      it.value().data->cache_cost);
 
-            if (it.value().data->ref != 0)
+            if (it.value().data->ref.load() != 0)
                 in_use_cost += it.value().data->cache_cost / it.value().data->cache_count;
         }
 
@@ -2882,7 +2881,7 @@ void QFontCache::timerEvent(QTimerEvent *)
         EngineDataCache::Iterator it = engineDataCache.begin(),
                                  end = engineDataCache.end();
         while (it != end) {
-            if (it.value()->ref != 0) {
+            if (it.value()->ref.load() != 0) {
                 ++it;
                 continue;
             }
@@ -2910,7 +2909,7 @@ void QFontCache::timerEvent(QTimerEvent *)
         uint least_popular = ~0u;
 
         for (; it != end; ++it) {
-            if (it.value().data->ref != 0)
+            if (it.value().data->ref.load() != 0)
                 continue;
 
             if (it.value().timestamp < oldest &&
@@ -2923,7 +2922,7 @@ void QFontCache::timerEvent(QTimerEvent *)
         FC_DEBUG("    oldest %u least popular %u", oldest, least_popular);
 
         for (it = engineCache.begin(); it != end; ++it) {
-            if (it.value().data->ref == 0 &&
+            if (it.value().data->ref.load() == 0 &&
                  it.value().timestamp == oldest &&
                  it.value().hits == least_popular)
                 break;
@@ -2932,7 +2931,7 @@ void QFontCache::timerEvent(QTimerEvent *)
         if (it != end) {
             FC_DEBUG("    %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'",
                      it.value().data, it.value().timestamp, it.value().hits,
-                     int(it.value().data->ref), it.value().data->cache_count,
+                     it.value().data->ref.load(), it.value().data->cache_count,
                      it.value().data->name());
 
             if (--it.value().data->cache_count == 0) {
index 3f00806..067a630 100644 (file)
@@ -168,9 +168,8 @@ static HB_Error hb_getSFntTable(void *font, HB_Tag tableTag, HB_Byte *buffer, HB
 // QFontEngine
 
 QFontEngine::QFontEngine()
-    : QObject()
+    : QObject(), ref(0)
 {
-    ref = 0;
     cache_count = 0;
     fsType = 0;
     symbol = false;
@@ -1360,7 +1359,7 @@ QFontEngineMulti::~QFontEngineMulti()
         QFontEngine *fontEngine = engines.at(i);
         if (fontEngine) {
             fontEngine->ref.deref();
-            if (fontEngine->cache_count == 0 && fontEngine->ref == 0)
+            if (fontEngine->cache_count == 0 && fontEngine->ref.load() == 0)
                 delete fontEngine;
         }
     }
index 0457202..2ab339e 100644 (file)
@@ -138,7 +138,7 @@ QGlyphRun::~QGlyphRun()
 */
 void QGlyphRun::detach()
 {
-    if (d->ref != 1)
+    if (d->ref.load() != 1)
         d.detach();
 }
 
index 80ad31c..8d5a920 100644 (file)
@@ -194,7 +194,7 @@ QSupportedWritingSystems::~QSupportedWritingSystems()
 */
 void QSupportedWritingSystems::detach()
 {
-    if (d->ref != 1) {
+    if (d->ref.load() != 1) {
         QWritingSystemsPrivate *newd = new QWritingSystemsPrivate(d);
         if (!d->ref.deref())
             delete d;
index 389c5bd..8fccd9b 100644 (file)
@@ -683,7 +683,7 @@ void QRawFont::setPixelSize(qreal pixelSize)
         d->fontEngine->ref.ref();
 
     oldFontEngine->ref.deref();
-    if (oldFontEngine->cache_count == 0 && oldFontEngine->ref == 0)
+    if (oldFontEngine->cache_count == 0 && oldFontEngine->ref.load() == 0)
         delete oldFontEngine;
 }
 
@@ -695,7 +695,7 @@ void QRawFontPrivate::cleanUp()
     platformCleanUp();
     if (fontEngine != 0) {
         fontEngine->ref.deref();
-        if (fontEngine->cache_count == 0 && fontEngine->ref == 0)
+        if (fontEngine->cache_count == 0 && fontEngine->ref.load() == 0)
             delete fontEngine;
         fontEngine = 0;
     }
index 1f2e957..992cb2f 100644 (file)
@@ -84,7 +84,7 @@ public:
 
     ~QRawFontPrivate()
     {
-        Q_ASSERT(ref == 0);
+        Q_ASSERT(ref.load() == 0);
         cleanUp();
     }
 
index bed0da6..a52cf25 100644 (file)
@@ -177,7 +177,7 @@ QStaticText::QStaticText(const QStaticText &other)
 */
 QStaticText::~QStaticText()
 {
-    Q_ASSERT(!data || data->ref >= 1);
+    Q_ASSERT(!data || data->ref.load() >= 1);
 }
 
 /*!
@@ -185,7 +185,7 @@ QStaticText::~QStaticText()
 */
 void QStaticText::detach()
 {    
-    if (data->ref != 1)
+    if (data->ref.load() != 1)
         data.detach();
 }
 
index 3a2431d..08d3a4d 100644 (file)
@@ -1219,7 +1219,7 @@ static inline void releaseCachedFontEngine(QFontEngine *fontEngine)
 {
     if (fontEngine) {
         fontEngine->ref.deref();
-        if (fontEngine->cache_count == 0 && fontEngine->ref == 0)
+        if (fontEngine->cache_count == 0 && fontEngine->ref.load() == 0)
             delete fontEngine;
     }
 }
index 4dc2145..b761eb2 100644 (file)
@@ -96,19 +96,19 @@ bool QBearerEngine::configurationsInUse() const
 
     for (it = accessPointConfigurations.constBegin(),
          end = accessPointConfigurations.constEnd(); it != end; ++it) {
-        if (it.value()->ref > 1)
+        if (it.value()->ref.load() > 1)
             return true;
     }
 
     for (it = snapConfigurations.constBegin(),
          end = snapConfigurations.constEnd(); it != end; ++it) {
-        if (it.value()->ref > 1)
+        if (it.value()->ref.load() > 1)
             return true;
     }
 
     for (it = userChoiceConfigurations.constBegin(),
          end = userChoiceConfigurations.constEnd(); it != end; ++it) {
-        if (it.value()->ref > 1)
+        if (it.value()->ref.load() > 1)
             return true;
     }
 
index 1062663..6beb52c 100644 (file)
@@ -411,7 +411,7 @@ public:
 
 template<> void QSharedDataPointer<QNetworkProxyPrivate>::detach()
 {
-    if (d && d->ref == 1)
+    if (d && d->ref.load() == 1)
         return;
     QNetworkProxyPrivate *x = (d ? new QNetworkProxyPrivate(*d)
                                : new QNetworkProxyPrivate);
@@ -727,7 +727,7 @@ public:
 
 template<> void QSharedDataPointer<QNetworkProxyQueryPrivate>::detach()
 {
-    if (d && d->ref == 1)
+    if (d && d->ref.load() == 1)
         return;
     QNetworkProxyQueryPrivate *x = (d ? new QNetworkProxyQueryPrivate(*d)
                                     : new QNetworkProxyQueryPrivate);
index 38b8e44..52b2ae3 100644 (file)
@@ -333,7 +333,7 @@ QGLFormat::QGLFormat(QGL::FormatOptions options, int plane)
 */
 void QGLFormat::detach()
 {
-    if (d->ref != 1) {
+    if (d->ref.load() != 1) {
         QGLFormatPrivate *newd = new QGLFormatPrivate(d);
         if (!d->ref.deref())
             delete d;
@@ -4907,7 +4907,7 @@ void QGLContextGroup::addShare(const QGLContext *context, const QGLContext *shar
         return;
 
     // Make sure 'context' is not already shared with another group of contexts.
-    Q_ASSERT(context->d_ptr->group->m_refs == 1);
+    Q_ASSERT(context->d_ptr->group->m_refs.load() == 1);
 
     // Free 'context' group resources and make it use the same resources as 'share'.
     QGLContextGroup *group = share->d_ptr->group;
index 75c1bbe..60104c6 100644 (file)
@@ -106,7 +106,7 @@ extern QImage qt_gl_read_framebuffer(const QSize&, bool, bool);
 */
 void QGLFramebufferObjectFormat::detach()
 {
-    if (d->ref != 1) {
+    if (d->ref.load() != 1) {
         QGLFramebufferObjectFormatPrivate *newd
             = new QGLFramebufferObjectFormatPrivate(d);
         if (!d->ref.deref())
index 84ee475..8cdf40b 100644 (file)
@@ -983,8 +983,9 @@ void processPostedEvents(QCocoaEventDispatcherPrivate *const d, const bool block
         return;
     }
 
-    if (!d->threadData->canWait || (d->serialNumber != d->lastSerial)) {
-        d->lastSerial = d->serialNumber;
+    int serial = d->serialNumber.load();
+    if (!d->threadData->canWait || (serial != d->lastSerial)) {
+        d->lastSerial = serial;
         QWindowSystemInterface::sendWindowSystemEvents(d->q_func(), QEventLoop::AllEvents);
     }
 }
index cd36d5d..a53120c 100644 (file)
@@ -234,7 +234,7 @@ QSqlDatabasePrivate *QSqlDatabasePrivate::shared_null()
 
 void QSqlDatabasePrivate::invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn)
 {
-    if (db.d->ref != 1 && doWarn) {
+    if (db.d->ref.load() != 1 && doWarn) {
         qWarning("QSqlDatabasePrivate::removeDatabase: connection '%s' is still in use, "
                  "all queries will cease to work.", name.toLocal8Bit().constData());
         db.d->disable();
index 361730a..4eb46f1 100644 (file)
@@ -348,7 +348,7 @@ bool QSqlQuery::isNull(int field) const
 
 bool QSqlQuery::exec(const QString& query)
 {
-    if (d->ref != 1) {
+    if (d->ref.load() != 1) {
         bool fo = isForwardOnly();
         *this = QSqlQuery(driver()->createResult());
         d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy());
@@ -895,7 +895,7 @@ void QSqlQuery::clear()
 */
 bool QSqlQuery::prepare(const QString& query)
 {
-    if (d->ref != 1) {
+    if (d->ref.load() != 1) {
         bool fo = isForwardOnly();
         *this = QSqlQuery(driver()->createResult());
         setForwardOnly(fo);
index e1ba8d4..de7544f 100644 (file)
@@ -767,7 +767,7 @@ bool QIcon::isNull() const
  */
 bool QIcon::isDetached() const
 {
-    return !d || d->ref == 1;
+    return !d || d->ref.load() == 1;
 }
 
 /*! \internal
@@ -775,7 +775,7 @@ bool QIcon::isDetached() const
 void QIcon::detach()
 {
     if (d) {
-        if (d->ref != 1) {
+        if (d->ref.load() != 1) {
             QIconPrivate *x = new QIconPrivate;
             if (d->engine_version > 1) {
                 QIconEngineV2 *engine = static_cast<QIconEngineV2 *>(d->engine);
index 7c7cafc..29798d8 100644 (file)
@@ -4509,7 +4509,7 @@ void QDomElementPrivate::setAttributeNS(const QString& nsURI, const QString& qNa
 void QDomElementPrivate::removeAttribute(const QString& aname)
 {
     QDomNodePrivate* p = m_attr->removeNamedItem(aname);
-    if (p && p->ref == 0)
+    if (p && p->ref.load() == 0)
         delete p;
 }