From 5a6c73b1157b309ff1538d52dd0367939f3ee25e Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Wed, 31 Mar 2010 19:42:41 +0300 Subject: [PATCH] gettime fixes Return microseconds instead of nanoseconds. Also return value is now delta from the first call to gettime instead of the absolute value of the monotonic clock. Signed-off-by: Timo Kokkonen --- main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 1191251..84b180e 100644 --- a/main.c +++ b/main.c @@ -26,17 +26,21 @@ static void clear_buf(SDL_Surface *screen) /* Return time in microseconds */ -static unsigned long long gettime(void) +static unsigned long gettime(void) { struct timespec tp; - unsigned long long ret; + unsigned long ret; + static unsigned long start = 0; clock_gettime(CLOCK_MONOTONIC, &tp); ret = tp.tv_sec * 1000 * 1000; - ret += tp.tv_nsec; + ret += tp.tv_nsec / 1000; - return ret; + if (!start) + start = ret; + + return ret - start; } static int poll_events(SDL_Surface **screen, struct camera *cam, -- 2.45.0