From bae94bc77362b59a52c0f562e62ff96198dab9d0 Mon Sep 17 00:00:00 2001 From: Gurucharan Shetty Date: Mon, 3 Mar 2014 14:13:03 -0800 Subject: [PATCH] timeval: gettimeofday() for Windows. Use GetSystemTimePreciseAsFileTime() for gettimeofday(). GetSystemTimePreciseAsFileTime() provides the result that is more high resolution than just the microsecond that gittimeofday() in Linux provides. So we need to remove some additional precision. Signed-off-by: Gurucharan Shetty Acked-by: Ben Pfaff --- lib/timeval.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/timeval.c b/lib/timeval.c index 8745c502c..74efa59f2 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -402,9 +402,17 @@ clock_gettime(clock_t id, struct timespec *ts) void xgettimeofday(struct timeval *tv) { +#ifndef _WIN32 if (gettimeofday(tv, NULL) == -1) { VLOG_FATAL("gettimeofday failed (%s)", ovs_strerror(errno)); } +#else + ULARGE_INTEGER current_time = xgetfiletime(); + + tv->tv_sec = (current_time.QuadPart - unix_epoch.QuadPart) / 10000000; + tv->tv_usec = ((current_time.QuadPart - unix_epoch.QuadPart) % + 10000000) / 10; +#endif } void -- 2.43.0