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 <david.faure@kdab.com>bb10
parent
8249f490ff
commit
46078f3374
|
|
@ -82,8 +82,8 @@ public:
|
|||
void unlock()
|
||||
{
|
||||
if (locked) {
|
||||
if (mtx1) mtx1->unlock();
|
||||
if (mtx2) mtx2->unlock();
|
||||
if (mtx1) mtx1->unlock();
|
||||
locked = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue