diff options
Diffstat (limited to 'src/corelib/thread/qmutex.cpp')
-rw-r--r-- | src/corelib/thread/qmutex.cpp | 23 |
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 |