From 46078f33745659ec1770cb4a58f8e02b5a9f670b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 14 Oct 2016 10:37:57 +0200 Subject: [PATCH] QOrderedMutexLocker: unlock in reverse order of locking This is an improvement for the following reasons: - Should mutex locking allocate any kind of resource, unlocking in reverse order will free those resources in inverse order, which helps typical allocators. - If the lock pair is contended, by unlocking in the same order as locking, we were allowing the waiting thread to wake up to take the first lock just to find that the second lock is still held by someone else. The order of unlocking has no influence on the correct- ness of the algorithm. Change-Id: Id16b0342aef325c14a7bd8836d3a75db68ef2588 Reviewed-by: David Faure --- src/corelib/thread/qorderedmutexlocker_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/thread/qorderedmutexlocker_p.h b/src/corelib/thread/qorderedmutexlocker_p.h index 6402be92bf..65c41d4f21 100644 --- a/src/corelib/thread/qorderedmutexlocker_p.h +++ b/src/corelib/thread/qorderedmutexlocker_p.h @@ -82,8 +82,8 @@ public: void unlock() { if (locked) { - if (mtx1) mtx1->unlock(); if (mtx2) mtx2->unlock(); + if (mtx1) mtx1->unlock(); locked = false; } }