diff options
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qatomic.h | 2 | ||||
-rw-r--r-- | src/corelib/thread/qmutex.cpp | 24 | ||||
-rw-r--r-- | src/corelib/thread/qmutex_p.h | 10 | ||||
-rw-r--r-- | src/corelib/thread/qmutexpool.cpp | 12 | ||||
-rw-r--r-- | src/corelib/thread/qmutexpool_p.h | 2 | ||||
-rw-r--r-- | src/corelib/thread/qthread.cpp | 4 |
6 files changed, 26 insertions, 28 deletions
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index 6fe4d65832..0b72ce9adf 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -259,7 +259,7 @@ inline void qAtomicAssign(T *&d, T *x) template <typename T> inline void qAtomicDetach(T *&d) { - if (d->ref == 1) + if (d->ref.load() == 1) return; T *x = d; d = new T(*d); diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index e2da0adf17..959d1f958a 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -154,7 +154,7 @@ QMutex::~QMutex() delete static_cast<QRecursiveMutexPrivate *>(d.load()); else if (d.load()) { #ifndef Q_OS_LINUX - if (d.load()->possiblyUnlocked && tryLock()) { unlock(); return; } + if (d.load()->possiblyUnlocked.load() && tryLock()) { unlock(); return; } #endif qWarning("QMutex: destroying locked mutex"); } @@ -361,7 +361,7 @@ bool QBasicMutex::lockInternal(int timeout) return static_cast<QRecursiveMutexPrivate *>(d)->lock(timeout); } - if (timeout == 0 && !d->possiblyUnlocked) + if (timeout == 0 && !d->possiblyUnlocked.load()) return false; if (!d->ref()) @@ -375,7 +375,7 @@ bool QBasicMutex::lockInternal(int timeout) int old_waiters; do { - old_waiters = d->waiters; + old_waiters = d->waiters.load(); if (old_waiters == -QMutexPrivate::BigNumber) { // we are unlocking, and the thread that unlocks is about to change d to 0 // we try to aquire the mutex by changing to dummyLocked() @@ -407,7 +407,7 @@ bool QBasicMutex::lockInternal(int timeout) } if (d->wait(timeout)) { - if (d->possiblyUnlocked && d->possiblyUnlocked.testAndSetRelaxed(true, false)) + if (d->possiblyUnlocked.load() && d->possiblyUnlocked.testAndSetRelaxed(true, false)) d->deref(); d->derefWaiters(1); //we got the lock. (do not deref) @@ -445,7 +445,7 @@ void QBasicMutex::unlockInternal() if (d->waiters.fetchAndAddRelease(-QMutexPrivate::BigNumber) == 0) { //there is no one waiting on this mutex anymore, set the mutex as unlocked (d = 0) if (this->d.testAndSetRelease(d, 0)) { - if (d->possiblyUnlocked && d->possiblyUnlocked.testAndSetRelaxed(true, false)) + if (d->possiblyUnlocked.load() && d->possiblyUnlocked.testAndSetRelaxed(true, false)) d->deref(); } d->derefWaiters(0); @@ -479,10 +479,10 @@ QMutexPrivate *QMutexPrivate::allocate() int i = freelist()->next(); QMutexPrivate *d = &(*freelist())[i]; d->id = i; - Q_ASSERT(d->refCount == 0); + Q_ASSERT(d->refCount.load() == 0); Q_ASSERT(!d->recursive); - Q_ASSERT(!d->possiblyUnlocked); - Q_ASSERT(d->waiters == 0); + Q_ASSERT(!d->possiblyUnlocked.load()); + Q_ASSERT(d->waiters.load() == 0); d->refCount = 1; return d; } @@ -490,9 +490,9 @@ QMutexPrivate *QMutexPrivate::allocate() void QMutexPrivate::release() { Q_ASSERT(!recursive); - Q_ASSERT(refCount == 0); - Q_ASSERT(!possiblyUnlocked); - Q_ASSERT(waiters == 0); + Q_ASSERT(refCount.load() == 0); + Q_ASSERT(!possiblyUnlocked.load()); + Q_ASSERT(waiters.load() == 0); freelist()->release(id); } @@ -502,7 +502,7 @@ void QMutexPrivate::derefWaiters(int value) int old_waiters; int new_waiters; do { - old_waiters = waiters; + old_waiters = waiters.load(); new_waiters = old_waiters; if (new_waiters < 0) { new_waiters += QMutexPrivate::BigNumber; diff --git a/src/corelib/thread/qmutex_p.h b/src/corelib/thread/qmutex_p.h index 00f071ebef..00bda48e5b 100644 --- a/src/corelib/thread/qmutex_p.h +++ b/src/corelib/thread/qmutex_p.h @@ -79,21 +79,21 @@ public: int id; bool ref() { - Q_ASSERT(refCount >= 0); + Q_ASSERT(refCount.load() >= 0); int c; do { - c = refCount; + c = refCount.load(); if (c == 0) return false; } while (!refCount.testAndSetRelaxed(c, c + 1)); - Q_ASSERT(refCount >= 0); + Q_ASSERT(refCount.load() >= 0); return true; } void deref() { - Q_ASSERT(refCount >=0); + Q_ASSERT(refCount.load() >= 0); if (!refCount.deref()) release(); - Q_ASSERT(refCount >=0); + Q_ASSERT(refCount.load() >= 0); } void release(); static QMutexPrivate *allocate(); diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp index 49fb46b0f4..ef4e9560fb 100644 --- a/src/corelib/thread/qmutexpool.cpp +++ b/src/corelib/thread/qmutexpool.cpp @@ -99,7 +99,7 @@ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size) : mutexes(size), recursionMode(recursionMode) { for (int index = 0; index < mutexes.count(); ++index) { - mutexes[index] = 0; + mutexes[index].store(0); } } @@ -109,10 +109,8 @@ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size) */ QMutexPool::~QMutexPool() { - for (int index = 0; index < mutexes.count(); ++index) { - delete mutexes[index]; - mutexes[index] = 0; - } + for (int index = 0; index < mutexes.count(); ++index) + delete mutexes[index].load(); } /*! @@ -136,9 +134,9 @@ QMutex *QMutexPool::createMutex(int index) { // mutex not created, create one QMutex *newMutex = new QMutex(recursionMode); - if (!mutexes[index].testAndSetOrdered(0, newMutex)) + if (!mutexes[index].testAndSetRelease(0, newMutex)) delete newMutex; - return mutexes[index]; + return mutexes[index].load(); } /*! diff --git a/src/corelib/thread/qmutexpool_p.h b/src/corelib/thread/qmutexpool_p.h index fa9a734065..20449c24d4 100644 --- a/src/corelib/thread/qmutexpool_p.h +++ b/src/corelib/thread/qmutexpool_p.h @@ -69,7 +69,7 @@ public: inline QMutex *get(const void *address) { int index = uint(quintptr(address)) % mutexes.count(); - QMutex *m = mutexes[index]; + QMutex *m = mutexes[index].load(); if (m) return m; else diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 40cb258e7e..31332cd521 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -85,7 +85,7 @@ QThreadData::QThreadData(int initialRefCount) QThreadData::~QThreadData() { - Q_ASSERT(_ref == 0); + Q_ASSERT(_ref.load() == 0); // In the odd case that Qt is running on a secondary thread, the main // thread instance will have been dereffed asunder because of the deref in @@ -117,7 +117,7 @@ void QThreadData::ref() { #ifndef QT_NO_THREAD (void) _ref.ref(); - Q_ASSERT(_ref != 0); + Q_ASSERT(_ref.load() != 0); #endif } |