diff options
-rw-r--r-- | src/corelib/thread/qmutex_linux.cpp | 4 | ||||
-rw-r--r-- | tests/auto/corelib/thread/qmutex/tst_qmutex.cpp | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp index 1644469763..4f70014acb 100644 --- a/src/corelib/thread/qmutex_linux.cpp +++ b/src/corelib/thread/qmutex_linux.cpp @@ -188,8 +188,8 @@ bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = - QElapsedTimer elapsedTimer; checkElapsedTimerIsTrivial(); if (IsTimed) { - ts.tv_sec = timeout / Q_INT64_C(1000) / 1000 / 1000; - ts.tv_nsec = timeout % Q_INT64_C(1000) * 1000 * 1000; + ts.tv_sec = timeout / 1000; + ts.tv_nsec = (timeout % 1000) * 1000 * 1000; elapsedTimer.start(); } diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 3c199b7fc3..7e3e720739 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -132,6 +132,14 @@ void tst_QMutex::tryLock() normalMutex.unlock(); testsTurn.release(); + // TEST 7 overflow: thread can acquire lock, timeout = 3000 (QTBUG-24795) + threadsTurn.acquire(); + timer.start(); + QVERIFY(normalMutex.tryLock(3000)); + QVERIFY(timer.elapsed() < 3000); + normalMutex.unlock(); + testsTurn.release(); + threadsTurn.acquire(); } }; @@ -175,6 +183,13 @@ void tst_QMutex::tryLock() normalMutex.unlock(); threadsTurn.release(); + // TEST 7: thread can acquire lock, timeout = 3000 (QTBUG-24795) + testsTurn.acquire(); + normalMutex.lock(); + threadsTurn.release(); + QThread::msleep(100); + normalMutex.unlock(); + // wait for thread to finish testsTurn.acquire(); threadsTurn.release(); |