Add GetTimeMs/Us().

SVN revision: 55888
This commit is contained in:
Kim Woelders 2011-01-05 18:05:50 +00:00
parent 4c25a12232
commit 568ee2489f
4 changed files with 52 additions and 3 deletions

View File

@ -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)

View File

@ -151,6 +151,7 @@ LDADD = \
$(X_EXTRA_LIBS) \
$(E_X_LIBS) \
$(DBUS_LIBS) \
$(CLOCK_LIBS) \
-lX11 -lm
if BUILD_MODULES

View File

@ -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 <time.h>
#include <sys/time.h>
#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

View File

@ -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);