Ecore: ecore_time : Add a fast high-resolution monotonic clock

SVN revision: 59021
This commit is contained in:
Vincent Torri 2011-04-28 19:38:41 +00:00
parent 3d28fd82b3
commit b66f4ec297
1 changed files with 23 additions and 4 deletions

View File

@ -12,6 +12,10 @@
# include <Evil.h>
#endif
#if defined(__APPLE__) && defined(__MACH__)
# include <mach/mach_time.h>
#endif
#include "Ecore.h"
#include "ecore_private.h"
@ -19,6 +23,8 @@
#ifdef HAVE_CLOCK_GETTIME
static clockid_t _ecore_time_clock_id = -1;
#elif defined(__APPLE__) && defined(__MACH__)
static double _ecore_time_clock_conversion = 1e-9;
#endif
double _ecore_time_loop_time = -1.0;
@ -66,12 +72,12 @@ ecore_time_get(void)
}
return (double)t.tv_sec + (((double)t.tv_nsec) / 1000000000.0);
#else
# ifdef HAVE_EVIL
#elif HAVE_EVIL
return evil_time_get();
# else
#elif defined(__APPLE__) && defined(__MACH__)
return _ecore_time_clock_conversion * (double) mach_absolute_time();
#else
return ecore_time_unix_get();
# endif
#endif
}
@ -165,9 +171,22 @@ _ecore_time_init(void)
}
#else
# ifndef HAVE_EVIL
# if defined(__APPLE__) && defined(__MACH__)
mach_timebase_info_data_t info;
kern_return_t err = mach_timebase_info(&info);
if (err == 0)
{
_ecore_time_clock_conversion = 1e-9 * (double) info.numer / (double) info.denom;
}
else
{
WRN("Unable to get timebase info. Fallback to nanoseconds.");
}
# else
# warning "Your platform isn't supported yet"
CRIT("Platform does not support clock_gettime. "
"Fallback to unix time.");
# endif
# endif
#endif