diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2016-07-14 10:12:11 +0200 |
---|---|---|
committer | Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> | 2016-07-15 06:33:56 +0000 |
commit | 120ba68882883c58415cb4ee285b0eba4192e76e (patch) | |
tree | 53427fef4b08a5d5e8c06a7306ef9b2486671432 /src/corelib/thread | |
parent | a372cf5a80ec1a774f8f624b30b3c8209b800ec8 (diff) |
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 <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qreadwritelock.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
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) |