From 3adbcb58d590c48e5799bce7ded0157c26460f6c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 21 Dec 2012 11:41:30 -0800 Subject: 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) Reviewed-by: Olivier Goffart --- src/corelib/thread/qmutex_linux.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/corelib/thread/qmutex_linux.cpp') 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 &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 &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(d_ptr, timeout); } -- cgit v1.2.3