Stats: use GetProcessTimes() on WIN32 to determine MPD uptime

Don't use GTimer if the operating system is able to tell us the
uptime.
This commit is contained in:
Max Kellermann
2013-11-24 20:41:00 +01:00
parent e53a25cbae
commit 85b51e4e77
3 changed files with 51 additions and 2 deletions

View File

@@ -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

View File

@@ -38,4 +38,15 @@ gcc_pure
uint64_t
MonotonicClockUS();
#ifdef WIN32
/**
* Returns the uptime of the current process in seconds.
*/
gcc_pure
unsigned
GetProcessUptimeS();
#endif
#endif