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 <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2023-02-26 20:08:56 +02:00
parent be3dd0115b
commit 48e06db2c5
2 changed files with 4 additions and 86 deletions

View File

@ -10,11 +10,6 @@
#include "private/qobject_p.h"
#include "private/qabstracteventdispatcher_p.h"
#ifdef QTIMERINFO_DEBUG
# include <QDebug>
# include <QThread>
#endif
#include <sys/times.h>
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<seconds>(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 <<t->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);

View File

@ -15,15 +15,11 @@
// We mean it.
//
#include "qplatformdefs.h" // _POSIX_MONOTONIC_CLOCK-0
#include <QtCore/private/qglobal_p.h>
// #define QTIMERINFO_DEBUG
#include "qabstracteventdispatcher.h"
#include <sys/time.h> // struct timeval
#include <sys/time.h> // struct timespec
#include <chrono>
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<QTimerInfo*>
{
// state variables used by activateTimers()
QTimerInfo *firstTimerInfo;
QTimerInfo *firstTimerInfo = nullptr;
public:
QTimerInfoList();