diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-12-08 15:59:36 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-12-08 15:59:36 (GMT) |
commit | 3bce78f6e143883fdba413e134504485594e73b3 (patch) | |
tree | d6050c698a2298b983d65812dfc907446958fb9a | |
parent | ccc3497c8815c1bc686a85a88ca2810f99a0c1eb (diff) | |
download | Qt-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
-rw-r--r-- | src/corelib/thread/qorderedmutexlocker_p.h | 8 |
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; } |