aboutsummaryrefslogtreecommitdiffstats
path: root/src/system/Clock.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-11-24 21:14:38 +0100
committerMax Kellermann <max@duempel.org>2013-11-24 21:14:38 +0100
commit529b4bd185eb130580c09c24450d80d62c9ae769 (patch)
treea002854fefe89cb1eaa16ac0b45558e6ea20478f /src/system/Clock.cxx
parent85b51e4e779360a4f2ead4404bf4d6b547f6d49d (diff)
downloadmpd-529b4bd185eb130580c09c24450d80d62c9ae769.tar.gz
mpd-529b4bd185eb130580c09c24450d80d62c9ae769.tar.xz
mpd-529b4bd185eb130580c09c24450d80d62c9ae769.zip
Stats: use monotonic clock instead of GTimer
Reduce GLib usage.
Diffstat (limited to '')
-rw-r--r--src/system/Clock.cxx22
1 files changed, 22 insertions, 0 deletions
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
@@ -31,6 +31,28 @@
#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)
{
#ifdef WIN32