QMutex: de-inline lock(), unlock(), and tryLock()
See the discussion of this topic on the mailing list: http://lists.qt-project.org/pipermail/development/2012-May/003943.html The consensus is to not have these methods have inline code to actually acquire the lock (i.e. no atomic test-and-set or similar). QBasicMutex is unchanged, and continues to have inlined lock(), tryLock(), and unlock(). QMutexLocker has been changed to always call QMutex::lock() (even though the constructor takes a QBasicMutex parameter). Change-Id: Ic7d2d9d581e6b254c84fdfdd8ce6c425535a8078 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
61904b8cfc
commit
88da8b4878
@ -177,6 +177,10 @@ QMutex::~QMutex()
|
|||||||
|
|
||||||
\sa unlock()
|
\sa unlock()
|
||||||
*/
|
*/
|
||||||
|
void QMutex::lock()
|
||||||
|
{
|
||||||
|
QBasicMutex::lock();
|
||||||
|
}
|
||||||
|
|
||||||
/*! \fn bool QMutex::tryLock(int timeout)
|
/*! \fn bool QMutex::tryLock(int timeout)
|
||||||
|
|
||||||
@ -201,7 +205,10 @@ QMutex::~QMutex()
|
|||||||
|
|
||||||
\sa lock(), unlock()
|
\sa lock(), unlock()
|
||||||
*/
|
*/
|
||||||
|
bool QMutex::tryLock(int timeout)
|
||||||
|
{
|
||||||
|
return QBasicMutex::tryLock(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
/*! \fn void QMutex::unlock()
|
/*! \fn void QMutex::unlock()
|
||||||
Unlocks the mutex. Attempting to unlock a mutex in a different
|
Unlocks the mutex. Attempting to unlock a mutex in a different
|
||||||
@ -210,6 +217,10 @@ QMutex::~QMutex()
|
|||||||
|
|
||||||
\sa lock()
|
\sa lock()
|
||||||
*/
|
*/
|
||||||
|
void QMutex::unlock()
|
||||||
|
{
|
||||||
|
QBasicMutex::unlock();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn void QMutex::isRecursive()
|
\fn void QMutex::isRecursive()
|
||||||
|
@ -96,8 +96,16 @@ public:
|
|||||||
enum RecursionMode { NonRecursive, Recursive };
|
enum RecursionMode { NonRecursive, Recursive };
|
||||||
explicit QMutex(RecursionMode mode = NonRecursive);
|
explicit QMutex(RecursionMode mode = NonRecursive);
|
||||||
~QMutex();
|
~QMutex();
|
||||||
|
|
||||||
|
void lock();
|
||||||
|
bool tryLock(int timeout = 0);
|
||||||
|
void unlock();
|
||||||
|
|
||||||
|
using QBasicMutex::isRecursive;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QMutex)
|
Q_DISABLE_COPY(QMutex)
|
||||||
|
friend class QMutexLocker;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Q_CORE_EXPORT QMutexLocker
|
class Q_CORE_EXPORT QMutexLocker
|
||||||
@ -107,12 +115,9 @@ public:
|
|||||||
{
|
{
|
||||||
Q_ASSERT_X((reinterpret_cast<quintptr>(m) & quintptr(1u)) == quintptr(0),
|
Q_ASSERT_X((reinterpret_cast<quintptr>(m) & quintptr(1u)) == quintptr(0),
|
||||||
"QMutexLocker", "QMutex pointer is misaligned");
|
"QMutexLocker", "QMutex pointer is misaligned");
|
||||||
if (m) {
|
val = quintptr(m);
|
||||||
m->lock();
|
// relock() here ensures that we call QMutex::lock() instead of QBasicMutex::lock()
|
||||||
val = reinterpret_cast<quintptr>(m) | quintptr(1u);
|
relock();
|
||||||
} else {
|
|
||||||
val = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
inline ~QMutexLocker() { unlock(); }
|
inline ~QMutexLocker() { unlock(); }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user