aboutsummaryrefslogtreecommitdiffstats
path: root/src/system/Clock.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-11-24 20:41:00 +0100
committerMax Kellermann <max@duempel.org>2013-11-24 20:41:00 +0100
commit85b51e4e779360a4f2ead4404bf4d6b547f6d49d (patch)
treef97779dd6e936ba15c0437ceed13085452157829 /src/system/Clock.cxx
parente53a25cbaee50fdf6b9a4a118677709b47bac4cd (diff)
downloadmpd-85b51e4e779360a4f2ead4404bf4d6b547f6d49d.tar.gz
mpd-85b51e4e779360a4f2ead4404bf4d6b547f6d49d.tar.xz
mpd-85b51e4e779360a4f2ead4404bf4d6b547f6d49d.zip
Stats: use GetProcessTimes() on WIN32 to determine MPD uptime
Don't use GTimer if the operating system is able to tell us the uptime.
Diffstat (limited to 'src/system/Clock.cxx')
-rw-r--r--src/system/Clock.cxx26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/system/Clock.cxx b/src/system/Clock.cxx
index 347997a44..17b221c15 100644
--- a/src/system/Clock.cxx
+++ b/src/system/Clock.cxx
@@ -96,3 +96,29 @@ MonotonicClockUS(void)
#endif
}
+#ifdef WIN32
+
+gcc_const
+static unsigned
+DeltaFileTimeS(FILETIME a, FILETIME b)
+{
+ ULARGE_INTEGER a2, b2;
+ b2.LowPart = b.dwLowDateTime;
+ b2.HighPart = b.dwHighDateTime;
+ a2.LowPart = a.dwLowDateTime;
+ a2.HighPart = a.dwHighDateTime;
+ return (a2.QuadPart - b2.QuadPart) / 10000000;
+}
+
+unsigned
+GetProcessUptimeS()
+{
+ FILETIME creation_time, now;
+ GetProcessTimes(GetCurrentProcess(), &creation_time,
+ nullptr, nullptr, nullptr);
+ GetSystemTimeAsFileTime(&now);
+
+ return DeltaFileTimeS(now, creation_time);
+}
+
+#endif