qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 31/35] vhost-user-test: fix g_cond_wait_until compat implementation
Date: Wed, 29 Jun 2016 17:23:59 +0200	[thread overview]
Message-ID: <1467213840-14206-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1467213840-14206-1-git-send-email-pbonzini@redhat.com>

This fixes compilation with glib versions up to 2.30, such
as the one in CentOS 6.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/glib-compat.h   | 26 ++++++++++++++++++++++++++
 tests/vhost-user-test.c | 17 ++---------------
 2 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/include/glib-compat.h b/include/glib-compat.h
index 03d8b12..01aa7b3 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -149,6 +149,32 @@ static inline void (g_cond_signal)(CompatGCond *cond)
 }
 #undef g_cond_signal
 
+static inline gboolean (g_cond_timed_wait)(CompatGCond *cond,
+                                           CompatGMutex *mutex,
+                                           GTimeVal *time)
+{
+    g_assert(mutex->once.status != G_ONCE_STATUS_PROGRESS);
+    g_once(&cond->once, do_g_cond_new, NULL);
+    return g_cond_timed_wait((GCond *) cond->once.retval,
+                             (GMutex *) mutex->once.retval, time);
+}
+#undef g_cond_timed_wait
+
+/* This is not a macro, because it didn't exist until 2.32.  */
+static inline gboolean g_cond_wait_until(CompatGCond *cond, CompatGMutex *mutex,
+                                         gint64 end_time)
+{
+    GTimeVal time;
+
+    /* Convert from monotonic to CLOCK_REALTIME.  */
+    end_time -= g_get_monotonic_time();
+    g_get_current_time(&time);
+    end_time += time.tv_sec * G_TIME_SPAN_SECOND + time.tv_usec;
+
+    time.tv_sec = end_time / G_TIME_SPAN_SECOND;
+    time.tv_usec = end_time % G_TIME_SPAN_SECOND;
+    return g_cond_timed_wait(cond, mutex, &time);
+}
 
 /* before 2.31 there was no g_thread_new() */
 static inline GThread *g_thread_new(const char *name,
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index 8b2164b..421d432 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -127,25 +127,12 @@ typedef struct TestServer {
     int fds_num;
     int fds[VHOST_MEMORY_MAX_NREGIONS];
     VhostUserMemory memory;
-    GMutex data_mutex;
-    GCond data_cond;
+    CompatGMutex data_mutex;
+    CompatGCond data_cond;
     int log_fd;
     uint64_t rings;
 } TestServer;
 
-#if !GLIB_CHECK_VERSION(2, 32, 0)
-static gboolean g_cond_wait_until(CompatGCond cond, CompatGMutex mutex,
-                                  gint64 end_time)
-{
-    gboolean ret = FALSE;
-    end_time -= g_get_monotonic_time();
-    GTimeVal time = { end_time / G_TIME_SPAN_SECOND,
-                      end_time % G_TIME_SPAN_SECOND };
-    ret = g_cond_timed_wait(cond, mutex, &time);
-    return ret;
-}
-#endif
-
 static const char *tmpfs;
 static const char *root;
 
-- 
1.8.3.1

  reply	other threads:[~2016-06-29 15:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-29 15:23 [Qemu-devel] [PULL v2 00/35] Misc patches for QEMU soft freeze Paolo Bonzini
2016-06-29 15:23 ` Paolo Bonzini [this message]
2016-06-29 15:24 ` [Qemu-devel] [PULL 32/35] vhost-user: disable chardev handlers on close Paolo Bonzini
2016-06-29 15:31   ` Marc-André Lureau
2016-06-29 15:45     ` Paolo Bonzini
2016-06-30  8:59 ` [Qemu-devel] [PULL v2 00/35] Misc patches for QEMU soft freeze Peter Maydell
2016-06-30 13:11   ` Paolo Bonzini

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=1467213840-14206-2-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.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 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).