From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH] glib: add compatibility interface for g_get_monotonic_time()
Date: Wed, 15 Oct 2014 09:24:28 +0200 [thread overview]
Message-ID: <1413357868-31569-1-git-send-email-stefanha@redhat.com> (raw)
This patch fixes compilation errors when building against glib <2.28.0
due to the missing g_get_monotonic_time() function.
The compilation error in tests/libqos/virtio.c was introduced in commit
70556264a89a268efba1d7e8e341adcdd7881eb4 ("libqos: use microseconds
instead of iterations for virtio timeout").
Add a simple g_get_monotonic_time() implementation to compat-glib.h
based on code from vhost-user-test.c.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/glib-compat.h | 14 ++++++++++++++
tests/vhost-user-test.c | 18 +-----------------
2 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 4ae0671..9343742 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -26,6 +26,20 @@ static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function,
}
#endif
+#if !GLIB_CHECK_VERSION(2, 28, 0)
+static inline gint64 g_get_monotonic_time(void)
+{
+ /* g_get_monotonic_time() is best-effort so we can use the wall clock as a
+ * fallback.
+ */
+
+ GTimeVal time;
+ g_get_current_time(&time);
+
+ return time.tv_sec * G_TIME_SPAN_SECOND + time.tv_usec;
+}
+#endif
+
#ifdef _WIN32
/*
* g_poll has a problem on Windows when using
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index 75fedf0..af4012e 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -26,10 +26,6 @@
#define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000))
#endif
-#if GLIB_CHECK_VERSION(2, 28, 0)
-#define HAVE_MONOTONIC_TIME
-#endif
-
#if GLIB_CHECK_VERSION(2, 32, 0)
#define HAVE_MUTEX_INIT
#define HAVE_COND_INIT
@@ -116,18 +112,6 @@ static VhostUserMemory memory;
static GMutex *data_mutex;
static GCond *data_cond;
-static gint64 _get_time(void)
-{
-#ifdef HAVE_MONOTONIC_TIME
- return g_get_monotonic_time();
-#else
- GTimeVal time;
- g_get_current_time(&time);
-
- return time.tv_sec * G_TIME_SPAN_SECOND + time.tv_usec;
-#endif
-}
-
static GMutex *_mutex_new(void)
{
GMutex *mutex;
@@ -210,7 +194,7 @@ static void read_guest_mem(void)
g_mutex_lock(data_mutex);
- end_time = _get_time() + 5 * G_TIME_SPAN_SECOND;
+ end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
while (!fds_num) {
if (!_cond_wait_until(data_cond, data_mutex, end_time)) {
/* timeout has passed */
--
1.9.3
next reply other threads:[~2014-10-15 7:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-15 7:24 Stefan Hajnoczi [this message]
2014-10-15 7:37 ` [Qemu-devel] [PATCH] glib: add compatibility interface for g_get_monotonic_time() Igor Mammedov
2014-10-15 10:10 ` [Qemu-devel] [PATCH v2] " Igor Mammedov
2014-10-15 10:47 ` Peter Maydell
2014-10-15 12:29 ` [Qemu-devel] [PATCH v3] " Igor Mammedov
2014-10-15 12:38 ` Stefan Hajnoczi
2014-10-15 12:47 ` Peter Maydell
2014-10-15 19:38 ` Peter Maydell
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=1413357868-31569-1-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=dgilbert@redhat.com \
--cc=peter.maydell@linaro.org \
--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 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).