QTimerInfo: correct CoarseTimer beyond the [20ms,20s] range earlier
Simplifies some code. Change-Id: I83dda2d36c904517b3c0fffd17b3d18f2dfbc2b3 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit afa86c60e6b6513c5c34b3832a5ece526c071c3f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
dc5894b865
commit
e5b3dca681
@ -286,8 +286,19 @@ void QTimerInfoList::registerTimer(int timerId, qint64 interval, Qt::TimerType t
|
|||||||
void QTimerInfoList::registerTimer(int timerId, milliseconds interval,
|
void QTimerInfoList::registerTimer(int timerId, milliseconds interval,
|
||||||
Qt::TimerType timerType, QObject *object)
|
Qt::TimerType timerType, QObject *object)
|
||||||
{
|
{
|
||||||
QTimerInfo *t = new QTimerInfo(timerId, interval, timerType, object);
|
// correct the timer type first
|
||||||
|
if (timerType == Qt::CoarseTimer) {
|
||||||
|
// this timer has up to 5% coarseness
|
||||||
|
// so our boundaries are 20 ms and 20 s
|
||||||
|
// below 20 ms, 5% inaccuracy is below 1 ms, so we convert to high precision
|
||||||
|
// above 20 s, 5% inaccuracy is above 1 s, so we convert to VeryCoarseTimer
|
||||||
|
if (interval >= 20s)
|
||||||
|
timerType = Qt::VeryCoarseTimer;
|
||||||
|
else if (interval <= 20ms)
|
||||||
|
timerType = Qt::PreciseTimer;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTimerInfo *t = new QTimerInfo(timerId, interval, timerType, object);
|
||||||
steady_clock::time_point expected = updateCurrentTime() + interval;
|
steady_clock::time_point expected = updateCurrentTime() + interval;
|
||||||
|
|
||||||
switch (timerType) {
|
switch (timerType) {
|
||||||
@ -298,23 +309,10 @@ void QTimerInfoList::registerTimer(int timerId, milliseconds interval,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Qt::CoarseTimer:
|
case Qt::CoarseTimer:
|
||||||
// this timer has up to 5% coarseness
|
t->timeout = expected;
|
||||||
// so our boundaries are 20 ms and 20 s
|
calculateCoarseTimerTimeout(t, currentTime);
|
||||||
// below 20 ms, 5% inaccuracy is below 1 ms, so we convert to high precision
|
break;
|
||||||
// above 20 s, 5% inaccuracy is above 1 s, so we convert to VeryCoarseTimer
|
|
||||||
if (interval >= 20s) {
|
|
||||||
t->timerType = Qt::VeryCoarseTimer;
|
|
||||||
} else {
|
|
||||||
t->timeout = expected;
|
|
||||||
if (interval <= 20ms) {
|
|
||||||
t->timerType = Qt::PreciseTimer;
|
|
||||||
// no adjustment is necessary
|
|
||||||
} else if (interval <= 20s) {
|
|
||||||
calculateCoarseTimerTimeout(t, currentTime);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Q_FALLTHROUGH();
|
|
||||||
case Qt::VeryCoarseTimer:
|
case Qt::VeryCoarseTimer:
|
||||||
t->interval = roundToSecs(t->interval);
|
t->interval = roundToSecs(t->interval);
|
||||||
const auto currentTimeInSecs = floor<seconds>(currentTime);
|
const auto currentTimeInSecs = floor<seconds>(currentTime);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user