From: Ed Swierk <eswierk@aristanetworks.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] slirp: Use monotonic clock if available
Date: Wed, 22 Jul 2009 15:49:05 -0700 [thread overview]
Message-ID: <1248302945.14831.4.camel@localhost.localdomain> (raw)
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
next reply other threads:[~2009-07-22 22:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-22 22:49 Ed Swierk [this message]
2009-07-22 23:38 ` [Qemu-devel] [PATCH] slirp: Use monotonic clock if available malc
2009-07-23 0:57 ` Ed Swierk
2009-07-23 6:40 ` [Qemu-devel] " Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1248302945.14831.4.camel@localhost.localdomain \
--to=eswierk@aristanetworks.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.