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);
}
inline ~QGlobalStaticDeleter()
{
- delete globalStatic.pointer;
- globalStatic.pointer = 0;
+ delete globalStatic.pointer.load();
+ globalStatic.pointer.store(0);
globalStatic.destroyed = true;
}
};
{ \
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) \
{ \
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) \
{ \
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())) { \
x.take(); \
} \
} \
- return thisGlobalStatic.pointer; \
+ return thisGlobalStatic.pointer.load(); \
}
#endif
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
}
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;
}
//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
*/
QMutex::QMutex(RecursionMode mode)
{
- if (mode == Recursive)
- d = new QRecursiveMutexPrivate;
- else
- d = 0;
+ d.store(mode == Recursive ? new QRecursiveMutexPrivate : 0);
}
/*!
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");
}
*/
bool QBasicMutex::isRecursive() {
- QMutexPrivate *d = this->d;
+ QMutexPrivate *d = this->d.load();
if (quintptr(d) <= 0x3)
return false;
return d->recursive;
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;
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;
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;
}
} 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
*/
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
}
inline void unlock() {
- Q_ASSERT(d); //mutex must be locked
+ Q_ASSERT(d.load()); //mutex must be locked
if (!d.testAndSetRelease(dummyLocked(), 0))
unlockInternal();
}
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
elapsedTimer.start();
while (!fastTryLock()) {
- QMutexPrivate *d = this->d;
+ QMutexPrivate *d = this->d.load();
if (!d) // if d is 0, the mutex is unlocked
continue;
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;
}
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;
}
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);
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;
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;
} 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;
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;
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;
};
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; }
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()
{
// 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
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
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)
qSwap(d, o);
qSwap(this->value, actual);
- if (!d || d->strongref == 0)
+ if (!d || d->strongref.load() == 0)
this->value = 0;
// dereference saved data
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; }
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");
}
}
- features = f;
- return features;
+ features.store(f);
+ return f;
}
void qDumpCPUFeatures()
void QRegion::detach()
{
- if (d->ref != 1)
+ if (d->ref.load() != 1)
*this = copy();
#if defined(Q_WS_X11)
else if (d->xrectangles) {
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;
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;
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;
{
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;
void QGLColormap::detach_helper()
{
QGLColormapData *x = new QGLColormapData;
- x->ref = 1;
+ x->ref.store(1);
x->cmapHandle = 0;
x->cells = 0;
if (d->cells) {
inline void QGLColormap::detach()
{
- if (d->ref != 1)
+ if (d->ref.load() != 1)
detach_helper();
}
return;
if (type != QtFatalMsg) {
- if (counter <= 0)
+ if (counter.load() <= 0)
return;
if (!counter.deref()) {
QBasicAtomicPointer<WFHC> p = Q_BASIC_ATOMIC_INITIALIZER(0);
- p->bar();
+ p.load()->bar();
WFHC *expectedValue = 0;
WFHC *newValue = 0;
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
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;
Q_OBJECT
public:
static int runCount;
- SingletonObject() { val = 42; ++runCount; }
+ SingletonObject() { val.store(42); ++runCount; }
~SingletonObject() { }
QBasicAtomicInt val;
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);
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);
delete parent;
QCOMPARE(controlVariable, 1);
- QCOMPARE((int)IncrementThread::runCount, NumberOfThreads);
+ QCOMPARE((int)IncrementThread::runCount.load(), NumberOfThreads);
QCOMPARE(SingletonObject::runCount, 1);
}
QVERIFY(tls.hasLocalData());
}
};
- int c = SPointer::count;
+ int c = SPointer::count.load();
QThreadStorage<QTBUG14579_class *> tls;
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 {
QVERIFY(QTBUG14579_resetTls()->hasLocalData());
}
};
- int c = SPointer::count;
+ int c = SPointer::count.load();
Thread t1;
Thread t2;
QVERIFY(t3.wait());
//check all the constructed things have been destructed
- QCOMPARE(int(SPointer::count), c);
+ QCOMPARE(int(SPointer::count.load()), c);
}
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);
QVERIFY(t2.wait());
QVERIFY(t3.wait());
- QCOMPARE(c, int(SPointer::count));
+ QCOMPARE(c, int(SPointer::count.load()));
}
return *this;
}
- int refCount() const { return d->ref; }
+ int refCount() const { return d->ref.load(); }
private:
RefCountingClassData *d;
};
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:
// 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:
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:
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
}
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;
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
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;
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>();
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()
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;
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>();
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());
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;
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>();
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()
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
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();