From 120ba68882883c58415cb4ee285b0eba4192e76e Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 14 Jul 2016 10:12:11 +0200 Subject: QReadWriteLock fast path for tryLock without timeout When one tries to lock without a timeout, there is no need to allocate a QReadWriteLockPrivate as we will not wait on it. Change-Id: I37c96a7fbc0c66fbdffe372f6089708cb2466fe3 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/thread/qreadwritelock.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/corelib/thread/qreadwritelock.cpp') diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index 5665bf74f6..6302a3a515 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -244,6 +244,9 @@ bool QReadWriteLock::tryLockForRead(int timeout) } if (d == dummyLockedForWrite) { + if (!timeout) + return false; + // locked for write, assign a d_ptr and wait. auto val = QReadWriteLockPrivate::allocate(); val->writerCount = 1; @@ -345,6 +348,9 @@ bool QReadWriteLock::tryLockForWrite(int timeout) } if (isUncontendedLocked(d)) { + if (!timeout) + return false; + // locked for either read or write, assign a d_ptr and wait. auto val = QReadWriteLockPrivate::allocate(); if (d == dummyLockedForWrite) -- cgit v1.2.3