diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2016-06-28 18:32:42 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-06-29 16:49:40 +0200 |
commit | 634d39b4e3e5736b73c55b0fcc113e81246a7057 (patch) | |
tree | 77024f54cf47a439e4b3ad9a4026b99bf2e345a9 /include/glib-compat.h | |
parent | 66f37d360b3fc91275ab6ca3de81f0d356c24b4a (diff) |
vhost-user-test: fix g_cond_wait_until compat implementation
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>
Diffstat (limited to 'include/glib-compat.h')
-rw-r--r-- | include/glib-compat.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/glib-compat.h b/include/glib-compat.h index 03d8b12675..01aa7b37a5 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, |