[ovs-dev] [PATCH 2/2] timeval: gettimeofday() for Windows.
Gurucharan Shetty
shettyg at nicira.com
Mon Mar 3 22:46:28 UTC 2014
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 at nicira.com>
---
lib/timeval.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/lib/timeval.c b/lib/timeval.c
index 07abb4c..5af891a 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -392,9 +392,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
--
1.7.9.5
More information about the dev
mailing list