From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeJ9T-0005Pr-Ev for qemu-devel@nongnu.org; Wed, 15 Oct 2014 03:37:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeJ9N-00078L-A4 for qemu-devel@nongnu.org; Wed, 15 Oct 2014 03:37:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7389) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeJ9N-00077p-1r for qemu-devel@nongnu.org; Wed, 15 Oct 2014 03:37:37 -0400 Date: Wed, 15 Oct 2014 09:37:32 +0200 From: Igor Mammedov Message-ID: <20141015093732.3ab2c370@igors-macbook-pro.local> In-Reply-To: <1413357868-31569-1-git-send-email-stefanha@redhat.com> References: <1413357868-31569-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] glib: add compatibility interface for g_get_monotonic_time() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Peter Maydell , qemu-devel@nongnu.org, "Dr. David Alan Gilbert" On Wed, 15 Oct 2014 09:24:28 +0200 Stefan Hajnoczi wrote: > 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 > --- > 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; G_TIME_SPAN_SECOND needs to be moved from tests/vhost-user-test.c to here as well. > +} > +#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 */