QTimerInfo::expected is only needed for debugging
authorBradley T. Hughes <bradley.hughes@nokia.com>
Thu, 5 Jan 2012 12:56:01 +0000 (13:56 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 6 Jan 2012 13:40:57 +0000 (14:40 +0100)
The code for calculating the expected time is only useful for debugging
purposes. Don't compile this into the library unless QTIMERINFO_DEBUG is
defined.

Change-Id: I6530e6a70410a12544410ef286225df98ceddcee
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/kernel/qtimerinfo_unix.cpp
src/corelib/kernel/qtimerinfo_unix_p.h

index c9ffee5..b89d4cc 100644 (file)
@@ -342,17 +342,18 @@ static void calculateNextTimeout(QTimerInfo *t, timeval currentTime)
     switch (t->timerType) {
     case Qt::PreciseTimer:
     case Qt::CoarseTimer:
-        t->expected += t->interval;
-        if (t->expected < currentTime) {
-            t->expected = currentTime;
-            t->expected += t->interval;
-        }
-
         t->timeout += t->interval;
         if (t->timeout < currentTime) {
             t->timeout = currentTime;
             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, currentTime);
         return;
@@ -362,7 +363,11 @@ static void calculateNextTimeout(QTimerInfo *t, timeval currentTime)
         t->timeout.tv_sec += t->interval;
         if (t->timeout.tv_sec <= currentTime.tv_sec)
             t->timeout.tv_sec = currentTime.tv_sec + 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;
     }
 
@@ -413,15 +418,16 @@ void QTimerInfoList::registerTimer(int timerId, int interval, Qt::TimerType time
     t->id = timerId;
     t->interval = interval;
     t->timerType = timerType;
-    t->expected = updateCurrentTime() + interval;
     t->obj = object;
     t->activateRef = 0;
 
+    timeval expected = updateCurrentTime() + interval;
+
     switch (timerType) {
     case Qt::PreciseTimer:
         // high precision timer is based on millisecond precision
         // so no adjustment is necessary
-        t->timeout = t->expected;
+        t->timeout = expected;
         break;
 
     case Qt::CoarseTimer:
@@ -433,7 +439,7 @@ void QTimerInfoList::registerTimer(int timerId, int interval, Qt::TimerType time
             t->timerType = Qt::VeryCoarseTimer;
             // fall through
         } else {
-            t->timeout = t->expected;
+            t->timeout = expected;
             if (interval <= 20) {
                 t->timerType = Qt::PreciseTimer;
                 // no adjustment is necessary
@@ -460,6 +466,7 @@ void QTimerInfoList::registerTimer(int timerId, int interval, Qt::TimerType time
     timerInsert(t);
 
 #ifdef QTIMERINFO_DEBUG
+    t->expected = expected;
     t->cumulativeError = 0;
     t->count = 0;
     if (t->timerType != Qt::PreciseTimer)
index 89d4d45..7f65138 100644 (file)
@@ -66,12 +66,12 @@ struct QTimerInfo {
     int id;           // - timer identifier
     int interval;     // - timer interval in milliseconds
     Qt::TimerType timerType; // - timer type
-    timeval expected; // when timer is expected to fire
     timeval 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