diff options
-rw-r--r-- | src/corelib/thread/qmutex.cpp | 13 | ||||
-rw-r--r-- | src/corelib/thread/qmutex.h | 17 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 145916d750..d310f56798 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -177,6 +177,10 @@ QMutex::~QMutex() \sa unlock() */ +void QMutex::lock() +{ + QBasicMutex::lock(); +} /*! \fn bool QMutex::tryLock(int timeout) @@ -201,7 +205,10 @@ QMutex::~QMutex() \sa lock(), unlock() */ - +bool QMutex::tryLock(int timeout) +{ + return QBasicMutex::tryLock(timeout); +} /*! \fn void QMutex::unlock() Unlocks the mutex. Attempting to unlock a mutex in a different @@ -210,6 +217,10 @@ QMutex::~QMutex() \sa lock() */ +void QMutex::unlock() +{ + QBasicMutex::unlock(); +} /*! \fn void QMutex::isRecursive() diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 0743c36457..22da73a8b8 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -96,8 +96,16 @@ public: enum RecursionMode { NonRecursive, Recursive }; explicit QMutex(RecursionMode mode = NonRecursive); ~QMutex(); + + void lock(); + bool tryLock(int timeout = 0); + void unlock(); + + using QBasicMutex::isRecursive; + private: Q_DISABLE_COPY(QMutex) + friend class QMutexLocker; }; class Q_CORE_EXPORT QMutexLocker @@ -107,12 +115,9 @@ public: { Q_ASSERT_X((reinterpret_cast<quintptr>(m) & quintptr(1u)) == quintptr(0), "QMutexLocker", "QMutex pointer is misaligned"); - if (m) { - m->lock(); - val = reinterpret_cast<quintptr>(m) | quintptr(1u); - } else { - val = 0; - } + val = quintptr(m); + // relock() here ensures that we call QMutex::lock() instead of QBasicMutex::lock() + relock(); } inline ~QMutexLocker() { unlock(); } |