Fix QMutex::tryLock timeout computation on Linux
The timeout is in millisecond. So we just need to divide by 1000 to get
the number of seconds
Regression introduced in f587e8f4fd
Reported in the comments of QTBUG-24795
Change-Id: Id16e05e7d04d33605860926f7516d14cdefd6a36
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
parent
162926414d
commit
2b308d4cb5
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue