*/
QMutex::QMutex(RecursionMode mode)
{
- d.store(mode == Recursive ? new QRecursiveMutexPrivate : 0);
+ d_ptr.store(mode == Recursive ? new QRecursiveMutexPrivate : 0);
}
/*!
QMutex::~QMutex()
{
if (isRecursive())
- delete static_cast<QRecursiveMutexPrivate *>(d.load());
- else if (d.load()) {
+ delete static_cast<QRecursiveMutexPrivate *>(d_ptr.load());
+ else if (d_ptr.load()) {
#ifndef Q_OS_LINUX
- if (d.load()->possiblyUnlocked.load() && tryLock()) { unlock(); return; }
+ if (d_ptr.load()->possiblyUnlocked.load() && tryLock()) { unlock(); return; }
#endif
qWarning("QMutex: destroying locked mutex");
}
*/
bool QBasicMutex::isRecursive() {
- QMutexPrivate *d = this->d.load();
+ QMutexPrivate *d = d_ptr.load();
if (quintptr(d) <= 0x3)
return false;
return d->recursive;
bool QBasicMutex::lockInternal(int timeout)
{
while (!fastTryLock()) {
- QMutexPrivate *d = this->d.loadAcquire();
+ QMutexPrivate *d = d_ptr.loadAcquire();
if (!d) // if d is 0, the mutex is unlocked
continue;
if (timeout == 0)
return false;
QMutexPrivate *newD = QMutexPrivate::allocate();
- if (!this->d.testAndSetOrdered(d, newD)) {
+ if (!d_ptr.testAndSetOrdered(d, newD)) {
//Either the mutex is already unlocked, or another thread already set it.
newD->deref();
continue;
if (!d->ref())
continue; //that QMutexPrivate was already released
- if (d != this->d.loadAcquire()) {
+ if (d != d_ptr.loadAcquire()) {
//Either the mutex is already unlocked, or relocked with another mutex
d->deref();
continue;
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()
- if (this->d.testAndSetAcquire(d, dummyLocked())) {
+ if (d_ptr.testAndSetAcquire(d, dummyLocked())) {
// Mutex aquired
Q_ASSERT(d->waiters.load() == -QMutexPrivate::BigNumber || d->waiters.load() == 0);
d->waiters = 0;
d->deref();
return true;
} else {
- Q_ASSERT(d != this->d.load()); //else testAndSetAcquire should have succeeded
+ Q_ASSERT(d != d_ptr.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;
}
} while (!d->waiters.testAndSetRelaxed(old_waiters, old_waiters + 1));
- if (d != this->d.loadAcquire()) {
+ if (d != d_ptr.loadAcquire()) {
// Mutex was unlocked.
if (old_waiters != QMutexPrivate::BigNumber) {
//we did not break the previous loop
d->deref();
d->derefWaiters(1);
//we got the lock. (do not deref)
- Q_ASSERT(d == this->d.load());
+ Q_ASSERT(d == d_ptr.load());
return true;
} else {
Q_ASSERT(timeout >= 0);
return false;
}
}
- Q_ASSERT(this->d.load() != 0);
+ Q_ASSERT(d_ptr.load() != 0);
return true;
}
*/
void QBasicMutex::unlockInternal()
{
- QMutexPrivate *d = this->d.loadAcquire();
+ QMutexPrivate *d = d_ptr.loadAcquire();
Q_ASSERT(d); //we must be locked
Q_ASSERT(d != dummyLocked()); // testAndSetRelease(dummyLocked(), 0) failed
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_ptr.testAndSetRelease(d, 0)) {
if (d->possiblyUnlocked.load() && d->possiblyUnlocked.testAndSetRelaxed(true, false))
d->deref();
}
}
inline void unlock() {
- Q_ASSERT(d.load()); //mutex must be locked
- if (!d.testAndSetRelease(dummyLocked(), 0))
+ Q_ASSERT(d_ptr.load()); //mutex must be locked
+ if (!d_ptr.testAndSetRelease(dummyLocked(), 0))
unlockInternal();
}
private:
inline bool fastTryLock() {
- return d.testAndSetAcquire(0, dummyLocked());
+ return d_ptr.testAndSetAcquire(0, dummyLocked());
}
bool lockInternal(int timeout = -1);
void unlockInternal();
- QBasicAtomicPointer<QMutexPrivate> d;
+ QBasicAtomicPointer<QMutexPrivate> d_ptr;
static inline QMutexPrivate *dummyLocked() {
return reinterpret_cast<QMutexPrivate *>(quintptr(1));
}
elapsedTimer.start();
while (!fastTryLock()) {
- QMutexPrivate *d = this->d.load();
+ QMutexPrivate *d = d_ptr.load();
if (!d) // if d is 0, the mutex is unlocked
continue;
if (quintptr(d) <= 0x3) { //d == dummyLocked() || d == dummyFutexValue()
if (timeout == 0)
return false;
- while (this->d.fetchAndStoreAcquire(dummyFutexValue()) != 0) {
+ while (d_ptr.fetchAndStoreAcquire(dummyFutexValue()) != 0) {
struct timespec ts, *pts = 0;
if (timeout >= 1) {
// recalculate the timeout
ts.tv_nsec = xtimeout % (Q_INT64_C(1000) * 1000 * 1000);
pts = &ts;
}
- int r = _q_futex(&this->d, FUTEX_WAIT, quintptr(dummyFutexValue()), pts);
+ int r = _q_futex(&d_ptr, FUTEX_WAIT, quintptr(dummyFutexValue()), pts);
if (r != 0 && errno == ETIMEDOUT)
return false;
}
Q_ASSERT(d->recursive);
return static_cast<QRecursiveMutexPrivate *>(d)->lock(timeout);
}
- Q_ASSERT(this->d.load());
+ Q_ASSERT(d_ptr.load());
return true;
}
void QBasicMutex::unlockInternal()
{
- QMutexPrivate *d = this->d.load();
+ QMutexPrivate *d = d_ptr.load();
Q_ASSERT(d); //we must be locked
Q_ASSERT(d != dummyLocked()); // testAndSetRelease(dummyLocked(), 0) failed
if (d == dummyFutexValue()) {
- this->d.fetchAndStoreRelease(0);
- _q_futex(&this->d, FUTEX_WAKE, 1, 0);
+ d_ptr.fetchAndStoreRelease(0);
+ _q_futex(&d_ptr, FUTEX_WAKE, 1, 0);
return;
}