summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/animation/qvariantanimation.cpp4
-rw-r--r--src/corelib/global/qglobal.h16
-rw-r--r--src/corelib/kernel/qmetatype.h8
-rw-r--r--src/corelib/kernel/qobject.cpp4
-rw-r--r--src/corelib/kernel/qobject_p.h2
-rw-r--r--src/corelib/thread/qmutex.cpp23
-rw-r--r--src/corelib/thread/qmutex.h2
-rw-r--r--src/corelib/thread/qmutex_linux.cpp12
-rw-r--r--src/corelib/tools/qcontiguouscache.h12
-rw-r--r--src/corelib/tools/qrefcount.h18
-rw-r--r--src/corelib/tools/qshareddata.h4
-rw-r--r--src/corelib/tools/qsharedpointer.cpp6
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h16
-rw-r--r--src/corelib/tools/qsimd.cpp8
-rw-r--r--src/gui/painting/qregion.cpp10
-rw-r--r--src/opengl/qglcolormap.cpp2
-rw-r--r--src/opengl/qglcolormap.h2
-rw-r--r--src/testlib/qtestlog.cpp2
-rw-r--r--tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp2
-rw-r--r--tests/auto/corelib/thread/qmutex/tst_qmutex.cpp2
-rw-r--r--tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp2
-rw-r--r--tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp8
-rw-r--r--tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp12
-rw-r--r--tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp80
25 files changed, 129 insertions, 130 deletions
diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp
index 4bfcd1db2a..7dfb4bddc1 100644
--- a/src/corelib/animation/qvariantanimation.cpp
+++ b/src/corelib/animation/qvariantanimation.cpp
@@ -292,11 +292,11 @@ void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress)
qSwap(currentValue, ret);
q->updateCurrentValue(currentValue);
static QBasicAtomicInt changedSignalIndex = Q_BASIC_ATOMIC_INITIALIZER(0);
- if (!changedSignalIndex) {
+ if (!changedSignalIndex.load()) {
//we keep the mask so that we emit valueChanged only when needed (for performance reasons)
changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)"));
}
- if (isSignalConnected(changedSignalIndex) && currentValue != ret) {
+ if (isSignalConnected(changedSignalIndex.load()) && currentValue != ret) {
//the value has changed
emit q->valueChanged(currentValue);
}
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 2d2db2440d..228c9a3469 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -1909,8 +1909,8 @@ public:
inline ~QGlobalStaticDeleter()
{
- delete globalStatic.pointer;
- globalStatic.pointer = 0;
+ delete globalStatic.pointer.load();
+ globalStatic.pointer.store(0);
globalStatic.destroyed = true;
}
};
@@ -1920,14 +1920,14 @@ public:
{ \
static QGlobalStatic<TYPE > thisGlobalStatic \
= { Q_BASIC_ATOMIC_INITIALIZER(0), false }; \
- if (!thisGlobalStatic.pointer && !thisGlobalStatic.destroyed) { \
+ if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { \
TYPE *x = new TYPE; \
if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) \
delete x; \
else \
static QGlobalStaticDeleter<TYPE > cleanup(thisGlobalStatic); \
} \
- return thisGlobalStatic.pointer; \
+ return thisGlobalStatic.pointer.load(); \
}
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \
@@ -1935,14 +1935,14 @@ public:
{ \
static QGlobalStatic<TYPE > thisGlobalStatic \
= { Q_BASIC_ATOMIC_INITIALIZER(0), false }; \
- if (!thisGlobalStatic.pointer && !thisGlobalStatic.destroyed) { \
+ if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { \
TYPE *x = new TYPE ARGS; \
if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) \
delete x; \
else \
static QGlobalStaticDeleter<TYPE > cleanup(thisGlobalStatic); \
} \
- return thisGlobalStatic.pointer; \
+ return thisGlobalStatic.pointer.load(); \
}
#define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER) \
@@ -1950,7 +1950,7 @@ public:
{ \
static QGlobalStatic<TYPE > thisGlobalStatic \
= { Q_BASIC_ATOMIC_INITIALIZER(0), false }; \
- if (!thisGlobalStatic.pointer && !thisGlobalStatic.destroyed) { \
+ if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { \
QScopedPointer<TYPE > x(new TYPE); \
INITIALIZER; \
if (thisGlobalStatic.pointer.testAndSetOrdered(0, x.data())) { \
@@ -1958,7 +1958,7 @@ public:
x.take(); \
} \
} \
- return thisGlobalStatic.pointer; \
+ return thisGlobalStatic.pointer.load(); \
}
#endif
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index 5df7658a13..f7473e337c 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -273,10 +273,10 @@ inline int qRegisterMetaTypeStreamOperators()
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
- if (!metatype_id) \
- metatype_id = qRegisterMetaType< TYPE >(#TYPE, \
- reinterpret_cast< TYPE *>(quintptr(-1))); \
- return metatype_id; \
+ if (!metatype_id.load()) \
+ metatype_id.storeRelease(qRegisterMetaType< TYPE >(#TYPE, \
+ reinterpret_cast< TYPE *>(quintptr(-1)))); \
+ return metatype_id.loadAcquire(); \
} \
}; \
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 0d7b840c3e..6e539d1722 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -808,13 +808,13 @@ QObject::~QObject()
}
if (d->sharedRefcount) {
- if (d->sharedRefcount->strongref > 0) {
+ if (d->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 = 0;
+ d->sharedRefcount->strongref.store(0);
if (!d->sharedRefcount->weakref.deref())
delete d->sharedRefcount;
}
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index e7233c5ba9..b4c30bd149 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -120,7 +120,7 @@ public:
//senders linked list
Connection *next;
Connection **prev;
- QBasicAtomicPointer<int> argumentTypes;
+ QAtomicPointer<int> argumentTypes;
ushort method_offset;
ushort method_relative;
ushort connectionType : 3; // 0 == auto, 1 == direct, 2 == queued, 4 == blocking
diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp
index c90b44be6c..b2f52500fa 100644
--- a/src/corelib/thread/qmutex.cpp
+++ b/src/corelib/thread/qmutex.cpp
@@ -140,10 +140,7 @@ QT_BEGIN_NAMESPACE
*/
QMutex::QMutex(RecursionMode mode)
{
- if (mode == Recursive)
- d = new QRecursiveMutexPrivate;
- else
- d = 0;
+ d.store(mode == Recursive ? new QRecursiveMutexPrivate : 0);
}
/*!
@@ -154,10 +151,10 @@ QMutex::QMutex(RecursionMode mode)
QMutex::~QMutex()
{
if (isRecursive())
- delete static_cast<QRecursiveMutexPrivate *>(d._q_value);
- else if (d) {
+ delete static_cast<QRecursiveMutexPrivate *>(d.load());
+ else if (d.load()) {
#ifndef Q_OS_LINUX
- if (d->possiblyUnlocked && tryLock()) { unlock(); return; }
+ if (d.load()->possiblyUnlocked && tryLock()) { unlock(); return; }
#endif
qWarning("QMutex: destroying locked mutex");
}
@@ -236,7 +233,7 @@ QMutex::~QMutex()
*/
bool QBasicMutex::isRecursive() {
- QMutexPrivate *d = this->d;
+ QMutexPrivate *d = this->d.load();
if (quintptr(d) <= 0x3)
return false;
return d->recursive;
@@ -345,7 +342,7 @@ bool QBasicMutex::isRecursive() {
bool QBasicMutex::lockInternal(int timeout)
{
while (!fastTryLock()) {
- QMutexPrivate *d = this->d;
+ QMutexPrivate *d = this->d.loadAcquire();
if (!d) // if d is 0, the mutex is unlocked
continue;
@@ -370,7 +367,7 @@ bool QBasicMutex::lockInternal(int timeout)
if (!d->ref())
continue; //that QMutexPrivate was already released
- if (d != this->d) {
+ if (d != this->d.loadAcquire()) {
//Either the mutex is already unlocked, or relocked with another mutex
d->deref();
continue;
@@ -389,7 +386,7 @@ bool QBasicMutex::lockInternal(int timeout)
d->deref();
return true;
} else {
- Q_ASSERT(d != this->d); //else testAndSetAcquire should have succeeded
+ Q_ASSERT(d != this->d.load()); //else testAndSetAcquire should have succeeded
// Mutex is likely to bo 0, we should continue the outer-loop,
// set old_waiters to the magic value of BigNumber
old_waiters = QMutexPrivate::BigNumber;
@@ -398,7 +395,7 @@ bool QBasicMutex::lockInternal(int timeout)
}
} while (!d->waiters.testAndSetRelaxed(old_waiters, old_waiters + 1));
- if (d != this->d) {
+ if (d != this->d.loadAcquire()) {
// Mutex was unlocked.
if (old_waiters != QMutexPrivate::BigNumber) {
//we did not break the previous loop
@@ -436,7 +433,7 @@ bool QBasicMutex::lockInternal(int timeout)
*/
void QBasicMutex::unlockInternal()
{
- QMutexPrivate *d = this->d;
+ QMutexPrivate *d = this->d.loadAcquire();
Q_ASSERT(d); //we must be locked
Q_ASSERT(d != dummyLocked()); // testAndSetRelease(dummyLocked(), 0) failed
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index a49b981d01..4bc2c87cda 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -65,7 +65,7 @@ public:
}
inline void unlock() {
- Q_ASSERT(d); //mutex must be locked
+ Q_ASSERT(d.load()); //mutex must be locked
if (!d.testAndSetRelease(dummyLocked(), 0))
unlockInternal();
}
diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp
index 17015b8f84..a3ca150a31 100644
--- a/src/corelib/thread/qmutex_linux.cpp
+++ b/src/corelib/thread/qmutex_linux.cpp
@@ -54,7 +54,7 @@
QT_BEGIN_NAMESPACE
-static inline int _q_futex(QMutexPrivate *volatile *addr, int op, int val, const struct timespec *timeout)
+static inline int _q_futex(void *addr, int op, int val, const struct timespec *timeout)
{
volatile int *int_addr = reinterpret_cast<volatile int *>(addr);
#if Q_BYTE_ORDER == Q_BIG_ENDIAN && QT_POINTER_SIZE == 8
@@ -82,7 +82,7 @@ bool QBasicMutex::lockInternal(int timeout)
elapsedTimer.start();
while (!fastTryLock()) {
- QMutexPrivate *d = this->d;
+ QMutexPrivate *d = this->d.load();
if (!d) // if d is 0, the mutex is unlocked
continue;
@@ -103,7 +103,7 @@ bool QBasicMutex::lockInternal(int timeout)
ts.tv_nsec = xtimeout % (Q_INT64_C(1000) * 1000 * 1000);
pts = &ts;
}
- int r = _q_futex(&this->d._q_value, FUTEX_WAIT, quintptr(dummyFutexValue()), pts);
+ int r = _q_futex(&this->d, FUTEX_WAIT, quintptr(dummyFutexValue()), pts);
if (r != 0 && errno == ETIMEDOUT)
return false;
}
@@ -112,19 +112,19 @@ bool QBasicMutex::lockInternal(int timeout)
Q_ASSERT(d->recursive);
return static_cast<QRecursiveMutexPrivate *>(d)->lock(timeout);
}
- Q_ASSERT(this->d);
+ Q_ASSERT(this->d.load());
return true;
}
void QBasicMutex::unlockInternal()
{
- QMutexPrivate *d = this->d;
+ QMutexPrivate *d = this->d.load();
Q_ASSERT(d); //we must be locked
Q_ASSERT(d != dummyLocked()); // testAndSetRelease(dummyLocked(), 0) failed
if (d == dummyFutexValue()) {
this->d.fetchAndStoreRelease(0);
- _q_futex(&this->d._q_value, FUTEX_WAKE, 1, 0);
+ _q_futex(&this->d, FUTEX_WAKE, 1, 0);
return;
}
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index 526d8fbc17..e192edf0ab 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -105,8 +105,8 @@ public:
inline ~QContiguousCache() { if (!d) return; if (!d->ref.deref()) free(p); }
- inline void detach() { if (d->ref != 1) detach_helper(); }
- inline bool isDetached() const { return d->ref == 1; }
+ inline void detach() { if (d->ref.load() != 1) detach_helper(); }
+ inline bool isDetached() const { return d->ref.load() == 1; }
inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; }
QContiguousCache<T> &operator=(const QContiguousCache<T> &other);
@@ -185,7 +185,7 @@ void QContiguousCache<T>::detach_helper()
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
x.d = malloc(d->alloc);
- x.d->ref = 1;
+ x.d->ref.store(1);
x.d->count = d->count;
x.d->start = d->start;
x.d->offset = d->offset;
@@ -258,7 +258,7 @@ void QContiguousCache<T>::setCapacity(int asize)
template <typename T>
void QContiguousCache<T>::clear()
{
- if (d->ref == 1) {
+ if (d->ref.load() == 1) {
if (QTypeInfo<T>::isComplex) {
int oldcount = d->count;
T * i = p->array + d->start;
@@ -274,7 +274,7 @@ void QContiguousCache<T>::clear()
} else {
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
x.d = malloc(d->alloc);
- x.d->ref = 1;
+ x.d->ref.store(1);
x.d->alloc = d->alloc;
x.d->count = x.d->start = x.d->offset = 0;
x.d->sharable = true;
@@ -293,7 +293,7 @@ template <typename T>
QContiguousCache<T>::QContiguousCache(int cap)
{
d = malloc(cap);
- d->ref = 1;
+ d->ref.store(1);
d->alloc = cap;
d->count = d->start = d->offset = 0;
d->sharable = true;
diff --git a/src/corelib/tools/qrefcount.h b/src/corelib/tools/qrefcount.h
index e72ddf66b6..619f61e072 100644
--- a/src/corelib/tools/qrefcount.h
+++ b/src/corelib/tools/qrefcount.h
@@ -56,27 +56,29 @@ namespace QtPrivate
class RefCount
{
public:
- inline void ref() {
- if (atomic > 0)
+ inline void ref() {
+ if (atomic.load() > 0)
atomic.ref();
}
inline bool deref() {
- if (atomic <= 0)
+ if (atomic.load() <= 0)
return true;
return atomic.deref();
}
inline bool operator==(int value) const
- { return atomic.operator ==(value); }
+ { return atomic.load() == value; }
inline bool operator!=(int value) const
- { return atomic.operator !=(value); }
+ { return atomic.load() != value; }
inline bool operator!() const
- { return atomic.operator !(); }
+ { return !atomic.load(); }
inline operator int() const
- { return atomic.operator int(); }
+ { return atomic.load(); }
inline RefCount &operator=(int value)
- { atomic = value; return *this; }
+ { atomic.store(value); return *this; }
+ inline RefCount &operator=(const RefCount &other)
+ { atomic.store(other.atomic.load()); return *this; }
QBasicAtomicInt atomic;
};
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index 811b186e8b..6de6a19289 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -72,7 +72,7 @@ public:
typedef T Type;
typedef T *pointer;
- inline void detach() { if (d && d->ref != 1) detach_helper(); }
+ inline void detach() { if (d && d->ref.load() != 1) detach_helper(); }
inline T &operator*() { detach(); return *d; }
inline const T &operator*() const { return *d; }
inline T *operator->() { detach(); return d; }
@@ -145,7 +145,7 @@ public:
inline T *data() const { return d; }
inline const T *constData() const { return d; }
- inline void detach() { if (d && d->ref != 1) detach_helper(); }
+ inline void detach() { if (d && d->ref.load() != 1) detach_helper(); }
inline void reset()
{
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index 873a2bf0d9..e9ae3cb4da 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -1260,13 +1260,13 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
// we can create the refcount data because it doesn't exist
ExternalRefCountData *x = new ExternalRefCountData(Qt::Uninitialized);
- x->strongref = -1;
- x->weakref = 2; // the QWeakPointer that called us plus the QObject itself
+ x->strongref.store(-1);
+ 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();
}
- return d->sharedRefcount;
+ return d->sharedRefcount.loadAcquire();
}
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 47ad21a499..f03889106f 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -186,11 +186,11 @@ namespace QtSharedPointer {
inline ExternalRefCountData()
{
- strongref = 1;
- weakref = 1;
+ strongref.store(1);
+ weakref.store(1);
}
inline ExternalRefCountData(Qt::Initialization) { }
- virtual inline ~ExternalRefCountData() { Q_ASSERT(!weakref); Q_ASSERT(strongref <= 0); }
+ virtual inline ~ExternalRefCountData() { Q_ASSERT(!weakref.load()); Q_ASSERT(strongref.load() <= 0); }
// overridden by derived classes
// returns false to indicate caller should delete the pointer
@@ -432,12 +432,12 @@ namespace QtSharedPointer {
if (o) {
// increase the strongref, but never up from zero
// or less (-1 is used by QWeakPointer on untracked QObject)
- register int tmp = o->strongref;
+ register int tmp = o->strongref.load();
while (tmp > 0) {
// try to increment from "tmp" to "tmp + 1"
if (o->strongref.testAndSetRelaxed(tmp, tmp + 1))
break; // succeeded
- tmp = o->strongref; // failed, try again
+ tmp = o->strongref.load(); // failed, try again
}
if (tmp > 0)
@@ -448,7 +448,7 @@ namespace QtSharedPointer {
qSwap(d, o);
qSwap(this->value, actual);
- if (!d || d->strongref == 0)
+ if (!d || d->strongref.load() == 0)
this->value = 0;
// dereference saved data
@@ -577,14 +577,14 @@ public:
typedef const value_type &const_reference;
typedef qptrdiff difference_type;
- inline bool isNull() const { return d == 0 || d->strongref == 0 || value == 0; }
+ inline bool isNull() const { return d == 0 || d->strongref.load() == 0 || value == 0; }
#ifndef Q_CC_NOKIAX86
inline operator RestrictedBool() const { return isNull() ? 0 : &QWeakPointer::value; }
#else
inline operator bool() const { return isNull() ? 0 : &QWeakPointer::value; }
#endif
inline bool operator !() const { return isNull(); }
- inline T *data() const { return d == 0 || d->strongref == 0 ? 0 : value; }
+ inline T *data() const { return d == 0 || d->strongref.load() == 0 ? 0 : value; }
inline QWeakPointer() : d(0), value(0) { }
inline ~QWeakPointer() { if (d && !d->weakref.deref()) delete d; }
diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
index 9bfb956c42..3dfe38a4d1 100644
--- a/src/corelib/tools/qsimd.cpp
+++ b/src/corelib/tools/qsimd.cpp
@@ -382,8 +382,8 @@ const int features_count = (sizeof features_indices - 1) / (sizeof features_indi
uint qDetectCPUFeatures()
{
static QBasicAtomicInt features = Q_BASIC_ATOMIC_INITIALIZER(-1);
- if (features != -1)
- return features;
+ if (features.load() != -1)
+ return features.load();
uint f = detectProcessorFeatures();
QByteArray disable = qgetenv("QT_NO_CPU_FEATURE");
@@ -395,8 +395,8 @@ uint qDetectCPUFeatures()
}
}
- features = f;
- return features;
+ features.store(f);
+ return f;
}
void qDumpCPUFeatures()
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index f343fa9b4c..3f8e80c13d 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -261,7 +261,7 @@ QRegion::QRegion(int x, int y, int w, int h, RegionType t)
void QRegion::detach()
{
- if (d->ref != 1)
+ if (d->ref.load() != 1)
*this = copy();
#if defined(Q_WS_X11)
else if (d->xrectangles) {
@@ -3828,7 +3828,7 @@ QRegion::QRegion(const QRect &r, RegionType t)
d->ref.ref();
} else {
d = new QRegionData;
- d->ref = 1;
+ d->ref.store(1);
#if defined(Q_WS_X11)
d->rgn = 0;
d->xrectangles = 0;
@@ -3853,7 +3853,7 @@ QRegion::QRegion(const QPolygon &a, Qt::FillRule fillRule)
fillRule == Qt::WindingFill ? WindingRule : EvenOddRule);
if (qt_rgn) {
d = new QRegionData;
- d->ref = 1;
+ d->ref.store(1);
#if defined(Q_WS_X11)
d->rgn = 0;
d->xrectangles = 0;
@@ -3885,7 +3885,7 @@ QRegion::QRegion(const QBitmap &bm)
d->ref.ref();
} else {
d = new QRegionData;
- d->ref = 1;
+ d->ref.store(1);
#if defined(Q_WS_X11)
d->rgn = 0;
d->xrectangles = 0;
@@ -3935,7 +3935,7 @@ QRegion QRegion::copy() const
{
QRegion r;
QScopedPointer<QRegionData> x(new QRegionData);
- x->ref = 1;
+ x->ref.store(1);
#if defined(Q_WS_X11)
x->rgn = 0;
x->xrectangles = 0;
diff --git a/src/opengl/qglcolormap.cpp b/src/opengl/qglcolormap.cpp
index 492154ffcf..8ff2f9fa0a 100644
--- a/src/opengl/qglcolormap.cpp
+++ b/src/opengl/qglcolormap.cpp
@@ -154,7 +154,7 @@ QGLColormap & QGLColormap::operator=(const QGLColormap &map)
void QGLColormap::detach_helper()
{
QGLColormapData *x = new QGLColormapData;
- x->ref = 1;
+ x->ref.store(1);
x->cmapHandle = 0;
x->cells = 0;
if (d->cells) {
diff --git a/src/opengl/qglcolormap.h b/src/opengl/qglcolormap.h
index d9e6ff98eb..cc8519173b 100644
--- a/src/opengl/qglcolormap.h
+++ b/src/opengl/qglcolormap.h
@@ -94,7 +94,7 @@ private:
inline void QGLColormap::detach()
{
- if (d->ref != 1)
+ if (d->ref.load() != 1)
detach_helper();
}
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp
index acd1a49d44..c812f6c69b 100644
--- a/src/testlib/qtestlog.cpp
+++ b/src/testlib/qtestlog.cpp
@@ -221,7 +221,7 @@ namespace QTest {
return;
if (type != QtFatalMsg) {
- if (counter <= 0)
+ if (counter.load() <= 0)
return;
if (!counter.deref()) {
diff --git a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp
index 42e744aaa6..903f6de5bb 100644
--- a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp
+++ b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp
@@ -102,7 +102,7 @@ void tst_QAtomicPointer::warningFreeHelper()
QBasicAtomicPointer<WFHC> p = Q_BASIC_ATOMIC_INITIALIZER(0);
- p->bar();
+ p.load()->bar();
WFHC *expectedValue = 0;
WFHC *newValue = 0;
diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp
index 7ad6a98a4d..71a310bcfd 100644
--- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp
+++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp
@@ -486,7 +486,7 @@ void tst_QMutex::stressTest()
for (int i = 1; i < threadCount; ++i)
QVERIFY(threads[i].wait(10000));
QCOMPARE(StressTestThread::errorCount, 0);
- qDebug("locked %d times", int(StressTestThread::lockCount));
+ qDebug("locked %d times", int(StressTestThread::lockCount.load()));
}
class TryLockRaceThread : public QThread
diff --git a/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp b/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp
index b23e11b153..abd3d6bbef 100644
--- a/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp
+++ b/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp
@@ -75,7 +75,7 @@ QOnceControl::QOnceControl(QBasicAtomicInt *control)
d = 0;
gv = control;
// check if code has already run once
- if (*gv == 2) {
+ if (gv->loadAcquire() == 2) {
// uncontended case: it has already initialized
// no waiting
return;
diff --git a/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp b/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp
index 235829b268..041f801672 100644
--- a/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp
+++ b/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp
@@ -70,7 +70,7 @@ class SingletonObject: public QObject
Q_OBJECT
public:
static int runCount;
- SingletonObject() { val = 42; ++runCount; }
+ SingletonObject() { val.store(42); ++runCount; }
~SingletonObject() { }
QBasicAtomicInt val;
@@ -126,7 +126,7 @@ void tst_QThreadOnce::sameThread()
QCOMPARE(controlVariable, 1);
static QSingleton<SingletonObject> s;
- QTEST((int)s->val, "expectedValue");
+ QTEST((int)s->val.load(), "expectedValue");
s->val.ref();
QCOMPARE(SingletonObject::runCount, 1);
@@ -148,7 +148,7 @@ void tst_QThreadOnce::multipleThreads()
QCOMPARE(controlVariable, 0); // nothing must have set them yet
SingletonObject::runCount = 0;
- IncrementThread::runCount = 0;
+ IncrementThread::runCount.store(0);
// wait for all of them to be ready
sem2.acquire(NumberOfThreads);
@@ -159,7 +159,7 @@ void tst_QThreadOnce::multipleThreads()
delete parent;
QCOMPARE(controlVariable, 1);
- QCOMPARE((int)IncrementThread::runCount, NumberOfThreads);
+ QCOMPARE((int)IncrementThread::runCount.load(), NumberOfThreads);
QCOMPARE(SingletonObject::runCount, 1);
}
diff --git a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp
index e123fc4fea..4fc3981abf 100644
--- a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp
+++ b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp
@@ -358,7 +358,7 @@ void tst_QThreadStorage::QTBUG14579_leakInDestructor()
QVERIFY(tls.hasLocalData());
}
};
- int c = SPointer::count;
+ int c = SPointer::count.load();
QThreadStorage<QTBUG14579_class *> tls;
@@ -382,7 +382,7 @@ void tst_QThreadStorage::QTBUG14579_leakInDestructor()
QVERIFY(t3.wait());
//check all the constructed things have been destructed
- QCOMPARE(int(SPointer::count), c);
+ QCOMPARE(int(SPointer::count.load()), c);
}
class QTBUG14579_reset {
@@ -410,7 +410,7 @@ void tst_QThreadStorage::QTBUG14579_resetInDestructor()
QVERIFY(QTBUG14579_resetTls()->hasLocalData());
}
};
- int c = SPointer::count;
+ int c = SPointer::count.load();
Thread t1;
Thread t2;
@@ -423,7 +423,7 @@ void tst_QThreadStorage::QTBUG14579_resetInDestructor()
QVERIFY(t3.wait());
//check all the constructed things have been destructed
- QCOMPARE(int(SPointer::count), c);
+ QCOMPARE(int(SPointer::count.load()), c);
}
@@ -474,7 +474,7 @@ void tst_QThreadStorage::valueBased()
QThreadStorage<QString> tlsString;
QThreadStorage<int> tlsInt;
- int c = SPointer::count;
+ int c = SPointer::count.load();
Thread t1(tlsSPointer, tlsString, tlsInt);
Thread t2(tlsSPointer, tlsString, tlsInt);
@@ -494,7 +494,7 @@ void tst_QThreadStorage::valueBased()
QVERIFY(t2.wait());
QVERIFY(t3.wait());
- QCOMPARE(c, int(SPointer::count));
+ QCOMPARE(c, int(SPointer::count.load()));
}
diff --git a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp
index 0a0c999b31..076b6ca63b 100644
--- a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp
+++ b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp
@@ -351,7 +351,7 @@ public:
return *this;
}
- int refCount() const { return d->ref; }
+ int refCount() const { return d->ref.load(); }
private:
RefCountingClassData *d;
};
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index 65709e3afa..1c9818696e 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -207,8 +207,8 @@ void tst_QSharedPointer::basics()
QVERIFY(! (ptr == otherData));
QVERIFY(! (otherData == ptr));
}
- QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref == 1);
- QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref == 1);
+ QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1);
+ QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.load() == 1);
{
// create another object:
@@ -220,8 +220,8 @@ void tst_QSharedPointer::basics()
// otherData is deleted here
}
- QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref == 1);
- QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref == 1);
+ QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1);
+ QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.load() == 1);
{
// create a copy:
@@ -237,8 +237,8 @@ void tst_QSharedPointer::basics()
QCOMPARE(copy.data(), aData);
QVERIFY(copy == aData);
}
- QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref == 1);
- QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref == 1);
+ QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1);
+ QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.load() == 1);
{
// create a weak reference:
@@ -269,8 +269,8 @@ void tst_QSharedPointer::basics()
QVERIFY(strong == ptr);
QCOMPARE(strong.data(), aData);
}
- QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref == 1);
- QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref == 1);
+ QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1);
+ QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.load() == 1);
// aData is deleted here
}
@@ -555,15 +555,15 @@ void tst_QSharedPointer::upCast()
QVERIFY(baseptr == derivedptr);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QWeakPointer<DerivedData> derivedptr = qWeakPointerCast<DerivedData>(baseptr);
QVERIFY(baseptr == derivedptr);
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QWeakPointer<Data> weakptr = baseptr;
@@ -571,16 +571,16 @@ void tst_QSharedPointer::upCast()
QVERIFY(baseptr == derivedptr);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QSharedPointer<DerivedData> derivedptr = baseptr.staticCast<DerivedData>();
QVERIFY(baseptr == derivedptr);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
}
class OtherObject: public QObject
@@ -955,8 +955,8 @@ void tst_QSharedPointer::dynamicCast()
QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QWeakPointer<Data> weakptr = baseptr;
@@ -965,8 +965,8 @@ void tst_QSharedPointer::dynamicCast()
QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QSharedPointer<DerivedData> derivedptr = baseptr.dynamicCast<DerivedData>();
@@ -974,8 +974,8 @@ void tst_QSharedPointer::dynamicCast()
QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
}
void tst_QSharedPointer::dynamicCastDifferentPointers()
@@ -990,8 +990,8 @@ void tst_QSharedPointer::dynamicCastDifferentPointers()
QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QWeakPointer<Data> weakptr = baseptr;
@@ -1000,8 +1000,8 @@ void tst_QSharedPointer::dynamicCastDifferentPointers()
QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QSharedPointer<DiffPtrDerivedData> derivedptr = baseptr.dynamicCast<DiffPtrDerivedData>();
@@ -1009,8 +1009,8 @@ void tst_QSharedPointer::dynamicCastDifferentPointers()
QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
Stuffing *nakedptr = dynamic_cast<Stuffing *>(baseptr.data());
@@ -1035,8 +1035,8 @@ void tst_QSharedPointer::dynamicCastVirtualBase()
QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QWeakPointer<Data> weakptr = baseptr;
@@ -1045,8 +1045,8 @@ void tst_QSharedPointer::dynamicCastVirtualBase()
QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QSharedPointer<VirtualDerived> derivedptr = baseptr.dynamicCast<VirtualDerived>();
@@ -1054,8 +1054,8 @@ void tst_QSharedPointer::dynamicCastVirtualBase()
QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
}
void tst_QSharedPointer::dynamicCastFailure()
@@ -1067,15 +1067,15 @@ void tst_QSharedPointer::dynamicCastFailure()
QSharedPointer<DerivedData> derivedptr = qSharedPointerDynamicCast<DerivedData>(baseptr);
QVERIFY(derivedptr.isNull());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
{
QSharedPointer<DerivedData> derivedptr = baseptr.dynamicCast<DerivedData>();
QVERIFY(derivedptr.isNull());
}
- QCOMPARE(int(refCountData(baseptr)->weakref), 1);
- QCOMPARE(int(refCountData(baseptr)->strongref), 1);
+ QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1);
+ QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1);
}
#endif
@@ -1371,8 +1371,8 @@ void tst_QSharedPointer::creating()
QCOMPARE(Data::destructorCounter, 1);
// valgrind will complain here if something happened to the pointer
- QVERIFY(d->weakref == 1);
- QVERIFY(d->strongref == 0);
+ QVERIFY(d->weakref.load() == 1);
+ QVERIFY(d->strongref.load() == 0);
}
check();