From 568ee2489f3a5956c6db2e52999fb5a1f305dc98 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Wed, 5 Jan 2011 18:05:50 +0000 Subject: [PATCH] Add GetTimeMs/Us(). SVN revision: 55888 --- configure.ac | 10 ++++++++++ src/Makefile.am | 1 + src/timers.c | 39 ++++++++++++++++++++++++++++++++++++++- src/timers.h | 5 +++-- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 14f01517..08aa33ce 100644 --- a/configure.ac +++ b/configure.ac @@ -64,6 +64,16 @@ AM_LANGINFO_CODESET AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION([0.16.1]) +AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], + [AC_CHECK_LIB([rt], [clock_gettime], [have_clock_gettime=-lrt], + [have_clock_gettime=no])]) +if test "x$have_clock_gettime" != xno; then + AC_DEFINE(USE_MONOTONIC_CLOCK, 1, [Use monotonic clock from clock_gettime()]) + if test "x$have_clock_gettime" != xyes; then + AC_SUBST(CLOCK_LIBS, [$have_clock_gettime]) + fi +fi + AC_ARG_ENABLE(hints-gnome, [ --enable-hints-gnome compile with GNOME(<2.0) hints support @<:@default=no@:>@],, enable_hints_gnome=no) diff --git a/src/Makefile.am b/src/Makefile.am index 9a04ba58..7fc43b1d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -151,6 +151,7 @@ LDADD = \ $(X_EXTRA_LIBS) \ $(E_X_LIBS) \ $(DBUS_LIBS) \ + $(CLOCK_LIBS) \ -lX11 -lm if BUILD_MODULES diff --git a/src/timers.c b/src/timers.c index 839f7be7..798afee2 100644 --- a/src/timers.c +++ b/src/timers.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2006-2009 Kim Woelders + * Copyright (C) 2006-2011 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -24,6 +24,7 @@ #include "E.h" #include "e16-ecore_list.h" #include "timers.h" +#include #include #define DEBUG_TIMERS 0 @@ -46,6 +47,42 @@ GetTime(void) return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000); } +unsigned int +GetTimeMs(void) +{ +#if USE_MONOTONIC_CLOCK + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + + return (unsigned int)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); +#else + struct timeval timev; + + gettimeofday(&timev, NULL); + + return (unsigned int)(timev.tv_sec * 1000 + timev.tv_usec / 1000); +#endif +} + +unsigned int +GetTimeUs(void) +{ +#if USE_MONOTONIC_CLOCK + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + + return (unsigned int)(ts.tv_sec * 1000000 + ts.tv_nsec / 1000); +#else + struct timeval timev; + + gettimeofday(&timev, NULL); + + return (unsigned int)(timev.tv_sec * 1000000 + timev.tv_usec); +#endif +} + static Timer *q_first = NULL; static void diff --git a/src/timers.h b/src/timers.h index e2fab7b8..0e49b126 100644 --- a/src/timers.h +++ b/src/timers.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2009 Kim Woelders + * Copyright (C) 2004-2011 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -26,8 +26,9 @@ #include "etypes.h" -/* timers.c */ double GetTime(void); +unsigned int GetTimeMs(void); +unsigned int GetTimeUs(void); Timer *TimerAdd(double in_time, int (*func) (void *data), void *data);