summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
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 /src/corelib/tools
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 'src/corelib/tools')
-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
6 files changed, 33 insertions, 31 deletions
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()