mark(): handle one second change properly
authorVincent Stehlé <v-stehle@ti.com>
Fri, 10 Aug 2012 15:59:40 +0000 (17:59 +0200)
committerVincent Stehlé <v-stehle@ti.com>
Fri, 10 Aug 2012 17:56:48 +0000 (19:56 +0200)
We handle one second change properly. Two seconds and more will still lead to
erroneous deltas.

Signed-off-by: Vincent Stehlé <v-stehle@ti.com>
util/util.h

index 80300aa9a92f9631f90000cac0ae0a819b8c3c65..53b6e1cd1689cc38422fdaceadf0dcacab1f6360 100644 (file)
@@ -189,6 +189,13 @@ mark(long *last)
        gettimeofday(&t, NULL);
        if (last) {
                long delta = t.tv_usec - *last;
+
+               /* Handle the case, where the seconds have changed.
+                * TODO: keep the whole timeval struct, to be able to cope with
+                * more than one second deltas? */
+               if (t.tv_usec < *last)
+                       delta += 1000000;
+
                *last = t.tv_usec;
                return delta;
        }