From 48e06db2c5ed542a9b99d3716599e0be2e2fc496 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sun, 26 Feb 2023 20:08:56 +0200 Subject: [PATCH] QTimerInfoList: cleanup - Initialize member in-class - Remove redundant include - Remove QTIMERINFO_DEBUG related code, it hasn't been compiled for a long time, so it has bit-rotted, and its purpose isn't clear any more Change-Id: I874415e1edec7c4da03f697f5f9f8665d8b015a3 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qtimerinfo_unix.cpp | 76 +------------------------- src/corelib/kernel/qtimerinfo_unix_p.h | 14 +---- 2 files changed, 4 insertions(+), 86 deletions(-) diff --git a/src/corelib/kernel/qtimerinfo_unix.cpp b/src/corelib/kernel/qtimerinfo_unix.cpp index 3be88c66eff..20b34e51c80 100644 --- a/src/corelib/kernel/qtimerinfo_unix.cpp +++ b/src/corelib/kernel/qtimerinfo_unix.cpp @@ -10,11 +10,6 @@ #include "private/qobject_p.h" #include "private/qabstracteventdispatcher_p.h" -#ifdef QTIMERINFO_DEBUG -# include -# include -#endif - #include using namespace std::chrono; @@ -30,10 +25,7 @@ Q_CORE_EXPORT bool qt_disable_lowpriority_timers=false; * timerBitVec array is used for keeping track of timer identifiers. */ -QTimerInfoList::QTimerInfoList() -{ - firstTimerInfo = nullptr; -} +QTimerInfoList::QTimerInfoList() = default; steady_clock::time_point QTimerInfoList::updateCurrentTime() { @@ -90,22 +82,6 @@ static constexpr seconds roundToSecs(milliseconds msecs) return secs; } -#ifdef QTIMERINFO_DEBUG -QDebug operator<<(QDebug s, timeval tv) -{ - QDebugStateSaver saver(s); - s.nospace() << tv.tv_sec << "." << qSetFieldWidth(6) << qSetPadChar(QChar(48)) << tv.tv_usec << Qt::reset; - return s; -} -QDebug operator<<(QDebug s, Qt::TimerType t) -{ - QDebugStateSaver saver(s); - s << (t == Qt::PreciseTimer ? "P" : - t == Qt::CoarseTimer ? "C" : "VC"); - return s; -} -#endif - static void calculateCoarseTimerTimeout(QTimerInfo *t, steady_clock::time_point now) { // The coarse timer works like this: @@ -230,13 +206,6 @@ static void calculateNextTimeout(QTimerInfo *t, steady_clock::time_point now) t->timeout = now; t->timeout += t->interval; } -#ifdef QTIMERINFO_DEBUG - t->expected += t->interval; - if (t->expected < currentTime) { - t->expected = currentTime; - t->expected += t->interval; - } -#endif if (t->timerType == Qt::CoarseTimer) calculateCoarseTimerTimeout(t, now); return; @@ -246,20 +215,8 @@ static void calculateNextTimeout(QTimerInfo *t, steady_clock::time_point now) t->timeout += t->interval; if (t->timeout <= now) t->timeout = time_point_cast(now + t->interval); -#ifdef QTIMERINFO_DEBUG - t->expected.tv_sec += t->interval; - if (t->expected.tv_sec <= currentTime.tv_sec) - t->expected.tv_sec = currentTime.tv_sec + t->interval; -#endif - return; + break; } - -#ifdef QTIMERINFO_DEBUG - if (t->timerType != Qt::PreciseTimer) - qDebug() << "timer" << t->timerType << Qt::hex << t->id << Qt::dec << "interval" << t->interval - << "originally expected at" << t->expected << "will fire at" << t->timeout - << "or" << (t->timeout - t->expected) << "s late"; -#endif } bool QTimerInfoList::timerWait(timespec &tm) @@ -362,15 +319,6 @@ void QTimerInfoList::registerTimer(int timerId, milliseconds interval, } timerInsert(t); - -#ifdef QTIMERINFO_DEBUG - t->expected = expected; - t->cumulativeError = 0; - t->count = 0; - if (t->timerType != Qt::PreciseTimer) - qDebug() << "timer" << t->timerType << Qt::hex <id << Qt::dec << "interval" << t->interval << "expected at" - << t->expected << "will fire first at" << t->timeout; -#endif } bool QTimerInfoList::unregisterTimer(int timerId) @@ -462,26 +410,6 @@ int QTimerInfoList::activateTimers() // remove from list removeFirst(); -#ifdef QTIMERINFO_DEBUG - float diff; - if (currentTime < currentTimerInfo->expected) { - // early - timeval early = currentTimerInfo->expected - currentTime; - diff = -(early.tv_sec + early.tv_usec / 1000000.0); - } else { - timeval late = currentTime - currentTimerInfo->expected; - diff = late.tv_sec + late.tv_usec / 1000000.0; - } - currentTimerInfo->cumulativeError += diff; - ++currentTimerInfo->count; - if (currentTimerInfo->timerType != Qt::PreciseTimer) - qDebug() << "timer" << currentTimerInfo->timerType << Qt::hex << currentTimerInfo->id << Qt::dec << "interval" - << currentTimerInfo->interval << "firing at" << currentTime - << "(orig" << currentTimerInfo->expected << "scheduled at" << currentTimerInfo->timeout - << ") off by" << diff << "activation" << currentTimerInfo->count - << "avg error" << (currentTimerInfo->cumulativeError / currentTimerInfo->count); -#endif - // determine next timeout time calculateNextTimeout(currentTimerInfo, now); diff --git a/src/corelib/kernel/qtimerinfo_unix_p.h b/src/corelib/kernel/qtimerinfo_unix_p.h index 70d5dd85fbd..ecea6006d38 100644 --- a/src/corelib/kernel/qtimerinfo_unix_p.h +++ b/src/corelib/kernel/qtimerinfo_unix_p.h @@ -15,15 +15,11 @@ // We mean it. // -#include "qplatformdefs.h" // _POSIX_MONOTONIC_CLOCK-0 - #include -// #define QTIMERINFO_DEBUG - #include "qabstracteventdispatcher.h" -#include // struct timeval +#include // struct timespec #include QT_BEGIN_NAMESPACE @@ -36,18 +32,12 @@ struct QTimerInfo { std::chrono::steady_clock::time_point timeout; // - when to actually fire QObject *obj; // - object to receive event QTimerInfo **activateRef; // - ref from activateTimers - -#ifdef QTIMERINFO_DEBUG - timeval expected; // when timer is expected to fire - float cumulativeError; - uint count; -#endif }; class Q_CORE_EXPORT QTimerInfoList : public QList { // state variables used by activateTimers() - QTimerInfo *firstTimerInfo; + QTimerInfo *firstTimerInfo = nullptr; public: QTimerInfoList();