glib: add compatibility interface for g_get_monotonic_time()
PATCH 1/1 glib: add compatibility interface for g_get_monotonic_time()
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.
--- include/glib-compat.h | 14 ++++++++++++++ tests/vhost-user-test.c | 18 +----------------- 2 files changed, 15 insertions(+), 17 deletions(-)
include/glib-compat.h +14 -0
@@ -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
tests/vhost-user-test.c +1 -17
@@ -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 */
Signature · 1 line
1.9.3
Quoted 29 lines · On Wed, 15 Oct 2014 09:24:28 +0200 Stefan Hajnoczi <[email protected]> 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.cwas introduced in commit70556264a89a268efba1d7e8e341adcdd7881eb4("libqos: use microseconds instead of iterations for virtio timeout").Add a simple
g_get_monotonic_time()implementation tocompat-glib.hbased on code fromvhost-user-test.c.Signed-off-by Stefan Hajnoczi <[email protected]>--- include/glib-compat.h | 14 ++++++++++++++ tests/vhost-user-test.c | 18 +----------------- 2 files changed, 15 insertions(+), 17 deletions(-)include/glib-compat.h +4
-0@@ -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
include/glib-compat.h static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function, · line 39
Quoted 7 lines
include/glib-compat.h +7
-0+* 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.
Quoted 49 lines
include/glib-compat.h +3
-0+} +#endif +#ifdef _WIN32/* * g_poll has a problem on Windows when using tests/vhost-user-test.c +1
-17@@ -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 */
PATCH v2 1/1 glib: add compatibility interface for g_get_monotonic_time()
In reply to Stefan HajnocziFrom: Stefan Hajnoczi <[email protected]>
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.
---
v2: fix ibuild break beacuse of missing G_TIME_SPAN_SECOND in header
--- include/glib-compat.h | 19 +++++++++++++++++++ tests/vhost-user-test.c | 23 +---------------------- 2 files changed, 20 insertions(+), 22 deletions(-)
include/glib-compat.h +19 -0
@@ -18,6 +18,11 @@#include <glib.h> +/* GLIB version compatibility flags */ +#if !GLIB_CHECK_VERSION (2 ,26 ,0 ) +#define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000)) +#endif +#if !GLIB_CHECK_VERSION (2 ,14 ,0 )static inline guint g_timeout_add_seconds (guint interval,GSourceFunc function,gpointer data)
@@ -26,6 +31,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
tests/vhost-user-test.c +1 -22
@@ -21,15 +21,6 @@#include <sys/vfs.h> #include <qemu/sockets.h> -/* GLIB version compatibility flags */ -#if !GLIB_CHECK_VERSION (2 ,26 ,0 ) -#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 +107,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 +189,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 */
Signature · 1 line
1.9.3 (Apple Git-50)
Quoted 9 lines · Igor Mammedov
From: Stefan Hajnoczi <[email protected]>
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.cwas introduced in commit70556264a89a268efba1d7e8e341adcdd7881eb4("libqos: use microseconds instead of iterations for virtio timeout").
Quoted 5 lines
Add a simple
g_get_monotonic_time()implementation tocompat-glib.hbased on code fromvhost-user-test.c.Signed-off-by Stefan Hajnoczi <[email protected]>Signed-off-by Igor Mammedov <[email protected]>
Unfortunately this patch doesn't actually fix the test compile failure, because it puts the replacement implementation in compat-glib.h which is not included from the libqos sources.
Adding #include "compat-glib.h" to tests/libqtest.h seems to fix this.
-- PMM
PATCH v3 1/1 glib: add compatibility interface for g_get_monotonic_time()
From: Stefan Hajnoczi <[email protected]>
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 glib-compat.h based on code from vhost-user-test.c.
---
v3: include glib-compat.h into libqtest.h to fix another build breakage (Peter)
v2: fix build break beacuse of missing G_TIME_SPAN_SECOND in header
--- include/glib-compat.h | 19 +++++++++++++++++++ tests/libqtest.h | 1 + tests/vhost-user-test.c | 23 +---------------------- 3 files changed, 21 insertions(+), 22 deletions(-)
include/glib-compat.h +19 -0
@@ -18,6 +18,11 @@#include <glib.h> +/* GLIB version compatibility flags */ +#if !GLIB_CHECK_VERSION (2 ,26 ,0 ) +#define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000)) +#endif +#if !GLIB_CHECK_VERSION (2 ,14 ,0 )static inline guint g_timeout_add_seconds (guint interval,GSourceFunc function,gpointer data)
@@ -26,6 +31,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
tests/libqtest.h +1 -0
@@ -23,6 +23,7 @@#include <stdarg.h> #include <sys/types.h> #include "qapi/qmp/qdict.h" +#include "glib-compat.h" typedef struct QTestState QTestState ;
tests/vhost-user-test.c +1 -22
@@ -21,15 +21,6 @@#include <sys/vfs.h> #include <qemu/sockets.h> -/* GLIB version compatibility flags */ -#if !GLIB_CHECK_VERSION (2 ,26 ,0 ) -#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 +107,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 +189,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 */
Signature · 1 line
1.9.3 (Apple Git-50)
Quoted 14 lines · Igor Mammedov
From: Stefan Hajnoczi <[email protected]>
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.cwas introduced in commit70556264a89a268efba1d7e8e341adcdd7881eb4("libqos: use microseconds instead of iterations for virtio timeout").Add a simple
g_get_monotonic_time()implementation toglib-compat.hbased on code fromvhost-user-test.c.Signed-off-by Stefan Hajnoczi <[email protected]>Signed-off-by Igor Mammedov <[email protected]>
Quoted 8 lines
---
v3: includeglib-compat.hintolibqtest.hto fix another build breakage (Peter)
v2: fix build break beacuse of missingG_TIME_SPAN_SECONDin header--- include/glib-compat.h | 19 +++++++++++++++++++ tests/libqtest.h | 1 + tests/vhost-user-test.c | 23 +---------------------- 3 files changed, 21 insertions(+), 22 deletions(-)
Thanks Igor and Peter. I didn't have a machine with old glib for testing :(.
Stefan
Quoted 2 lines · Stefan Hajnoczi
Thanks Igor and Peter. I didn't have a machine with old glib for testing :(.
No problem. "Earliest supported glib version" is actually one of the configs I'd like to buildtest before pushing but don't conveniently have the ability to do. Maybe I could set up some kind of chroot...
-- PMM
Peter Maydell
AppliedQuoted 12 lines · Igor Mammedov
From: Stefan Hajnoczi <[email protected]>
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.cwas introduced in commit70556264a89a268efba1d7e8e341adcdd7881eb4("libqos: use microseconds instead of iterations for virtio timeout").Add a simple
g_get_monotonic_time()implementation toglib-compat.hbased on code fromvhost-user-test.c.
Quoted 6 lines
Signed-off-by Stefan Hajnoczi <[email protected]>Signed-off-by Igor Mammedov <[email protected]>---
v3: includeglib-compat.hintolibqtest.hto fix another build breakage (Peter)
v2: fix build break beacuse of missingG_TIME_SPAN_SECONDin header
---
Applied, thanks.
-- PMM