summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qmutex.cpp
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/thread/qmutex.cpp
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/thread/qmutex.cpp')
-rw-r--r--src/corelib/thread/qmutex.cpp23
1 files changed, 10 insertions, 13 deletions
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