timeval: gettimeofday() for Windows.
authorGurucharan Shetty <gshetty@nicira.com>
Mon, 3 Mar 2014 22:13:03 +0000 (14:13 -0800)
committerGurucharan Shetty <gshetty@nicira.com>
Wed, 5 Mar 2014 16:38:18 +0000 (08:38 -0800)
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 <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/timeval.c

index 8745c50..74efa59 100644 (file)
@@ -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