summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-08-11 14:08:39 +0200
committerQt by Nokia <qt-info@nokia.com>2012-09-14 03:45:50 +0200
commit870bd84a4ee53ea98fd232da18771b1525dac1a1 (patch)
treeb4f473f26f944352aeb2874ae61371183b5332d7 /src/corelib/thread
parent3acaa648f0ffd03c4695d0be7ed25e73724e4417 (diff)
Don't recheck about timeout == 0 during mutex locking
If the timeout wasn't zero, it can only become zero if we return from futex() with a non-timeout reason but subsequently expires while we're recalculating something. A side effect is that we try-lock a non-recursive mutex exactly once. Before this change, we'd fastTryLock() twice even with timeout == 0. Change-Id: I0af09fc2a84669a683a843fcf1513203b075dfb7 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qmutex_linux.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp
index e14660cc37..09db046f0f 100644
--- a/src/corelib/thread/qmutex_linux.cpp
+++ b/src/corelib/thread/qmutex_linux.cpp
@@ -123,17 +123,18 @@ bool QBasicMutex::lockInternal(int timeout) Q_DECL_NOTHROW
return static_cast<QRecursiveMutexPrivate *>(d)->lock(timeout);
}
+ if (timeout == 0)
+ return false;
+
QElapsedTimer elapsedTimer;
if (timeout >= 1)
elapsedTimer.start();
while (!fastTryLock()) {
d = d_ptr.load();
+
if (!d) // if d is 0, the mutex is unlocked
continue;
- if (timeout == 0)
- return false;
-
// the mutex is locked already, set a bit indicating we're waiting
while (d_ptr.fetchAndStoreAcquire(dummyFutexValue()) != 0) {
struct timespec ts, *pts = 0;