summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qorderedmutexlocker_p.h
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-12-08 15:59:36 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-12-08 15:59:36 (GMT)
commit3bce78f6e143883fdba413e134504485594e73b3 (patch)
treed6050c698a2298b983d65812dfc907446958fb9a /src/corelib/thread/qorderedmutexlocker_p.h
parentccc3497c8815c1bc686a85a88ca2810f99a0c1eb (diff)
downloadQt-3bce78f6e143883fdba413e134504485594e73b3.zip
Qt-3bce78f6e143883fdba413e134504485594e73b3.tar.gz
Qt-3bce78f6e143883fdba413e134504485594e73b3.tar.bz2
Optimize QOrderedMutexLocker
try first to lock without releasing the second mutex. If it succees at first (likely), we should not have deadlock, and we do not need to unlock and relock the first mutex Should help in ~QObject Reviewed-by: brad
Diffstat (limited to 'src/corelib/thread/qorderedmutexlocker_p.h')
-rw-r--r--src/corelib/thread/qorderedmutexlocker_p.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/corelib/thread/qorderedmutexlocker_p.h b/src/corelib/thread/qorderedmutexlocker_p.h
index c22ee5c..946d306 100644
--- a/src/corelib/thread/qorderedmutexlocker_p.h
+++ b/src/corelib/thread/qorderedmutexlocker_p.h
@@ -103,9 +103,11 @@ public:
mtx2->lock();
return true;
}
- mtx1->unlock();
- mtx2->lock();
- mtx1->lock();
+ if (!mtx2->tryLock()) {
+ mtx1->unlock();
+ mtx2->lock();
+ mtx1->lock();
+ }
return true;
}