From 3bce78f6e143883fdba413e134504485594e73b3 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 8 Dec 2009 16:59:36 +0100 Subject: 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 --- src/corelib/thread/qorderedmutexlocker_p.h | 8 +++++--- 1 file 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; } -- cgit v0.12