summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a1769e7)
raw | patch | inline | side by side (parent: a1769e7)
author | Vincent Stehlé <v-stehle@ti.com> | |
Fri, 10 Aug 2012 15:59:40 +0000 (17:59 +0200) | ||
committer | Vincent 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>
erroneous deltas.
Signed-off-by: Vincent Stehlé <v-stehle@ti.com>
util/util.h | patch | blob | history |
diff --git a/util/util.h b/util/util.h
index 80300aa9a92f9631f90000cac0ae0a819b8c3c65..53b6e1cd1689cc38422fdaceadf0dcacab1f6360 100644 (file)
--- a/util/util.h
+++ b/util/util.h
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;
}