Stats: use monotonic clock instead of GTimer
Reduce GLib usage.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user