summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qmutex.h
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2010-03-30 16:01:06 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-04-20 13:48:56 (GMT)
commitdab8d4c77795ed195f23e427945267e9e9a4df20 (patch)
treef4b0aac2ed27e90de891e825463249fe70a4998c /src/corelib/thread/qmutex.h
parent13732b74e07fe10e95f2601f6cf2d0be78467eaa (diff)
downloadQt-dab8d4c77795ed195f23e427945267e9e9a4df20.zip
Qt-dab8d4c77795ed195f23e427945267e9e9a4df20.tar.gz
Qt-dab8d4c77795ed195f23e427945267e9e9a4df20.tar.bz2
Micro optimisations in QMutexLocker
Reviewed-by: Thiago
Diffstat (limited to 'src/corelib/thread/qmutex.h')
-rw-r--r--src/corelib/thread/qmutex.h18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index 677412e..509f300 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -95,21 +95,23 @@ class Q_CORE_EXPORT QMutexLocker
{
public:
inline explicit QMutexLocker(QMutex *m)
- : val(reinterpret_cast<quintptr>(m))
{
- Q_ASSERT_X((val & quintptr(1u)) == quintptr(0),
+ Q_ASSERT_X((reinterpret_cast<quintptr>(m) & quintptr(1u)) == quintptr(0),
"QMutexLocker", "QMutex pointer is misaligned");
- relock();
+ if (m) {
+ m->lock();
+ val = reinterpret_cast<quintptr>(m) | quintptr(1u);
+ } else {
+ val = 0;
+ }
}
inline ~QMutexLocker() { unlock(); }
inline void unlock()
{
- if (val) {
- if ((val & quintptr(1u)) == quintptr(1u)) {
- val &= ~quintptr(1u);
- mutex()->unlock();
- }
+ if ((val & quintptr(1u)) == quintptr(1u)) {
+ val &= ~quintptr(1u);
+ mutex()->unlock();
}
}