From: Gurucharan Shetty Date: Mon, 3 Mar 2014 22:13:03 +0000 (-0800) Subject: timeval: gettimeofday() for Windows. X-Git-Tag: sliver-openvswitch-2.2.90-1~8^2~2 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=bae94bc77362b59a52c0f562e62ff96198dab9d0;p=sliver-openvswitch.git 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 --- 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