qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] slirp: Use monotonic clock if available
@ 2009-07-22 22:49 Ed Swierk
  2009-07-22 23:38 ` malc
  0 siblings, 1 reply; 4+ messages in thread
From: Ed Swierk @ 2009-07-22 22:49 UTC (permalink / raw)
  To: qemu-devel

Calling gettimeofday() to compute a time interval can cause problems if
the system clock jumps forwards or backwards; use
clock_gettime(CLOCK_MONOTONIC) instead if it is available.

Also remove some useless macros.

Signed-off-by: Ed Swierk <eswierk@aristanetworks.com>

---
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 4bc8a9d..3214c29 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -258,25 +258,30 @@ void slirp_cleanup(Slirp *slirp)
 /*
  * curtime kept to an accuracy of 1ms
  */
-#ifdef _WIN32
 static void updtime(void)
 {
+#ifdef _WIN32
     struct _timeb tb;
 
     _ftime(&tb);
 
     curtime = tb.time * 1000 + tb.millitm;
-}
 #else
-static void updtime(void)
-{
+#ifdef CLOCK_MONOTONIC
+    struct timespec tv;
+
+    clock_gettime(CLOCK_MONOTONIC, &tv);
+
+    curtime = tv.tv_sec * 1000 + tv.tv_nsec / 1000000;
+#else
     struct timeval tv;
 
     gettimeofday(&tv, NULL);
 
     curtime = tv.tv_sec * 1000 + tv.tv_usec / 1000;
-}
 #endif
+#endif
+}
 
 void slirp_select_fill(int *pnfds,
                        fd_set *readfds, fd_set *writefds, fd_set *xfds)
diff --git a/slirp/slirp.h b/slirp/slirp.h
index 22058cd..020412c 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -108,10 +108,6 @@ typedef unsigned char u_int8_t;
 #include <arpa/inet.h>
 #endif
 
-#ifdef GETTIMEOFDAY_ONE_ARG
-#define gettimeofday(x, y) gettimeofday(x)
-#endif
-
 /* Systems lacking strdup() definition in <string.h>. */
 #if defined(ultrix)
 char *strdup(const char *);
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index dbc8dfd..5a0e6c1 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -190,9 +190,6 @@
 #define NO_UNIX_SOCKETS
 #endif
 
-/* Define if gettimeofday only takes one argument */
-#undef GETTIMEOFDAY_ONE_ARG
-
 /* Define if you have revoke() */
 #undef HAVE_REVOKE
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-07-23  6:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-22 22:49 [Qemu-devel] [PATCH] slirp: Use monotonic clock if available Ed Swierk
2009-07-22 23:38 ` malc
2009-07-23  0:57   ` Ed Swierk
2009-07-23  6:40     ` [Qemu-devel] " Jan Kiszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).