summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-12-01 22:41:48 -0500
committerTavian Barnes <tavianator@gmail.com>2010-12-02 16:09:40 -0500
commitc1ef0cf577d6659a248180ed785efb37fe516082 (patch)
treef4144369532c347b956cbbd5503a2d85dd4ac4b1
parent014910bb35bb9e4952b7302a5d91234f6eaaca5b (diff)
downloaddimension-c1ef0cf577d6659a248180ed785efb37fe516082.tar.xz
Implement dmnsn_get_times() on Windows.
-rw-r--r--libdimension/platform.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/libdimension/platform.c b/libdimension/platform.c
index 8b6182d..a678cf4 100644
--- a/libdimension/platform.c
+++ b/libdimension/platform.c
@@ -130,6 +130,27 @@ dmnsn_get_times(dmnsn_timer *timer)
timer->real = (double)real/clk_tck;
timer->user = (double)buf.tms_utime/clk_tck;
timer->system = (double)buf.tms_stime/clk_tck;
+#elif defined(_WIN32)
+ FILETIME real;
+ GetSystemTimeAsFileTime(&real);
+
+ FILETIME user, system, creation, exit;
+ HANDLE current_process = GetCurrentProcess();
+ if (GetProcessTimes(current_process,
+ &creation, &exit, &system, &user) != 0)
+ {
+ timer->real
+ = (((uint64_t)real.dwHighDateTime << 32) + real.dwLowDateTime)/1.0e7;
+ timer->user
+ = (((uint64_t)user.dwHighDateTime << 32) + user.dwLowDateTime)/1.0e7;
+ timer->system
+ = (((uint64_t)system.dwHighDateTime << 32) + system.dwLowDateTime)/1.0e7;
+ } else {
+ dmnsn_error(DMNSN_SEVERITY_MEDIUM, "GetProcessTimes() failed.");
+ timer->real = 0.0;
+ timer->user = 0.0;
+ timer->system = 0.0;
+ }
#else
timer->real = 0.0;
timer->user = 0.0;