Stats: use monotonic clock instead of GTimer

Reduce GLib usage.
This commit is contained in:
Max Kellermann
2013-11-24 21:14:38 +01:00
parent 85b51e4e77
commit 529b4bd185
5 changed files with 36 additions and 15 deletions

View File

@@ -30,6 +30,28 @@
#endif
#endif
unsigned
MonotonicClockS(void)
{
#ifdef WIN32
return GetTickCount() / 1000;
#elif defined(__APPLE__) /* OS X does not define CLOCK_MONOTONIC */
static mach_timebase_info_data_t base;
if (base.denom == 0)
(void)mach_timebase_info(&base);
return (unsigned)((mach_absolute_time() * base.numer / 1000)
/ (1000000 * base.denom));
#elif defined(CLOCK_MONOTONIC)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec;
#else
/* we have no monotonic clock, fall back to time() */
return time(nullptr);
#endif
}
unsigned
MonotonicClockMS(void)
{

View File

@@ -24,6 +24,13 @@
#include <stdint.h>
/**
* Returns the value of a monotonic clock in seconds.
*/
gcc_pure
unsigned
MonotonicClockS();
/**
* Returns the value of a monotonic clock in milliseconds.
*/