summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorThiago Macieira <thiago@kde.org>2011-07-05 23:46:19 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-03 07:57:41 +0200
commit5bfeab8749ce6820d55135b81665a7231d3b1504 (patch)
tree152569571114c53d4cdfaa0013307267cb3379a6 /tests/auto
parent5613c9722adee921e16682c0a035f2a7567bd346 (diff)
Make all uses of QBasicAtomicInt and Pointer use load() and store()
Most of these changes are search-and-replace of d->ref ==, d->ref != and d->ref =. The QBasicAtomicPointer in QObjectPrivate::Connection didn't need to be basic, so I made it QAtomicPointer. Change-Id: Ie3271abd1728af599f9ab17c6f4868e475f17bb6 Reviewed-on: http://codereview.qt-project.org/5030 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/auto')
-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
7 files changed, 54 insertions, 54 deletions
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();