From 529b4bd185eb130580c09c24450d80d62c9ae769 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 24 Nov 2013 21:14:38 +0100 Subject: Stats: use monotonic clock instead of GTimer Reduce GLib usage. --- src/system/Clock.cxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/system/Clock.cxx') diff --git a/src/system/Clock.cxx b/src/system/Clock.cxx index 17b221c15..8fbd76d22 100644 --- a/src/system/Clock.cxx +++ b/src/system/Clock.cxx @@ -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) { -- cgit v1.2.3