From: Vincent Stehlé Date: Fri, 10 Aug 2012 15:59:40 +0000 (+0200) Subject: mark(): handle one second change properly X-Git-Tag: glsdk-6_00_00_07~19 X-Git-Url: https://git.ti.com/gitweb?p=glsdk%2Fomapdrmtest.git;a=commitdiff_plain;h=2c8dc152bcbfa783cc2b049afac9ede579a27d9c mark(): handle one second change properly We handle one second change properly. Two seconds and more will still lead to erroneous deltas. Signed-off-by: Vincent Stehlé --- diff --git a/util/util.h b/util/util.h index 80300aa..53b6e1c 100644 --- a/util/util.h +++ b/util/util.h @@ -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; }