summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-12-21 11:41:30 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-23 20:34:46 +0100
commit3adbcb58d590c48e5799bce7ded0157c26460f6c (patch)
tree2ce7eec2db115875fa451a9ece57c9625f00f6df /src
parent96d06124a1da7e2bbd8bda2fc8e762cb46af8204 (diff)
Fix QMutex::tryLock with negative values
The Linux futex implementation had a Q_ASSERT for positive values, but the documentation says that negative values should be interpreted as infinite (equal to lock()). Test that too. Change-Id: I2f96a502d672732781e88e49797756ca9a809121 Reviewed-by: David Faure (KDE) <faure@kde.org> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/thread/qmutex_linux.cpp5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp
index 4f70014acb..94aec0ede0 100644
--- a/src/corelib/thread/qmutex_linux.cpp
+++ b/src/corelib/thread/qmutex_linux.cpp
@@ -187,7 +187,7 @@ bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = -
struct timespec ts, *pts = 0;
QElapsedTimer elapsedTimer;
checkElapsedTimerIsTrivial();
- if (IsTimed) {
+ if (IsTimed && timeout > 0) {
ts.tv_sec = timeout / 1000;
ts.tv_nsec = (timeout % 1000) * 1000 * 1000;
elapsedTimer.start();
@@ -206,7 +206,7 @@ bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = -
ts.tv_sec = xtimeout / Q_INT64_C(1000) / 1000 / 1000;
ts.tv_nsec = xtimeout % (Q_INT64_C(1000) * 1000 * 1000);
}
- if (IsTimed)
+ if (IsTimed && timeout > 0)
pts = &ts;
// successfully set the waiting bit, now sleep
@@ -232,7 +232,6 @@ void QBasicMutex::lockInternal() Q_DECL_NOTHROW
bool QBasicMutex::lockInternal(int timeout) Q_DECL_NOTHROW
{
Q_ASSERT(!isRecursive());
- Q_ASSERT(timeout >= 0);
return lockInternal_helper<true>(d_ptr, timeout);
}