aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/support/time_win32.c
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-07-06 11:21:09 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-07-06 11:21:09 -0700
commit63a4e227130a9d3517118f0d62fdce3b2c70a4ae (patch)
tree8e48701faec9dcf4a9838b55ea22a4301b8f311f /src/core/support/time_win32.c
parentf1bff016319861348e6a0460954c35634ea452b2 (diff)
parent863fad71eaaf435cd28a891e26ef9c0fd3e7db6b (diff)
Merge branch 'footprints-on-the-sands-of-time' of github.com:ctiller/grpc into footprints-on-the-sands-of-time
Diffstat (limited to 'src/core/support/time_win32.c')
-rw-r--r--src/core/support/time_win32.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c
index d015133561..b5ce13c9d5 100644
--- a/src/core/support/time_win32.c
+++ b/src/core/support/time_win32.c
@@ -41,12 +41,34 @@
#include <sys/timeb.h>
#include <windows.h>
-gpr_timespec gpr_now(void) {
+static LARGE_INTEGER g_start_time;
+static double g_time_scale;
+
+void gpr_time_init(void) {
+ LARGE_INTEGER frequency;
+ QueryPerformanceFrequency(&frequency);
+ QueryPerformanceCounter(&g_start_time);
+ g_time_scale = 1.0 / frequency.QuadPart;
+}
+
+gpr_timespec gpr_now(gpr_clock_type clock) {
gpr_timespec now_tv;
struct _timeb now_tb;
- _ftime_s(&now_tb);
- now_tv.tv_sec = now_tb.time;
- now_tv.tv_nsec = now_tb.millitm * 1000000;
+ LARGE_INTEGER timestamp;
+ double now_dbl;
+ switch (clock) {
+ case GPR_CLOCK_REALTIME:
+ _ftime_s(&now_tb);
+ now_tv.tv_sec = now_tb.time;
+ now_tv.tv_nsec = now_tb.millitm * 1000000;
+ break;
+ case GPR_CLOCK_MONOTONIC:
+ QueryPerformanceCounter(&timestamp);
+ now_dbl = (timestamp.QuadPart - g_start_time.QuadPart) * g_time_scale;
+ now_tv.tv_sec = (time_t)now_dbl;
+ now_tv.tv_nsec = (int)((now_dbl - (double)now_tv.tv_sec) * 1e9);
+ break;
+ }
return now_tv;
}