From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAJdB-000177-4y for qemu-devel@nongnu.org; Mon, 03 Feb 2014 08:32:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WAJd5-0004XQ-4g for qemu-devel@nongnu.org; Mon, 03 Feb 2014 08:32:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:19534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAJd4-0004XH-S3 for qemu-devel@nongnu.org; Mon, 03 Feb 2014 08:32:03 -0500 From: Stefan Hajnoczi Date: Mon, 3 Feb 2014 14:31:49 +0100 Message-Id: <1391434310-9990-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1391434310-9990-1-git-send-email-stefanha@redhat.com> References: <1391434310-9990-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 2/3] glib: add g_thread_new() compat function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Anthony Liguori Implement g_thread_new() in terms of the deprecated g_thread_create(). The API was changed in glib 2.31.0. The compat function allows us to write modern code and avoid ifdefs. Signed-off-by: Stefan Hajnoczi --- coroutine-gthread.c | 13 +++---------- include/glib-compat.h | 13 +++++++++++++ trace/simple.c | 5 +---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/coroutine-gthread.c b/coroutine-gthread.c index d3e5b99..695c113 100644 --- a/coroutine-gthread.c +++ b/coroutine-gthread.c @@ -76,11 +76,6 @@ static inline void set_coroutine_key(CoroutineGThread *co, g_private_replace(&coroutine_key, co); } -static inline GThread *create_thread(GThreadFunc func, gpointer data) -{ - return g_thread_new("coroutine", func, data); -} - #else /* Handle older GLib versions */ @@ -104,15 +99,13 @@ static inline void set_coroutine_key(CoroutineGThread *co, free_on_thread_exit ? (GDestroyNotify)g_free : NULL); } +#endif + static inline GThread *create_thread(GThreadFunc func, gpointer data) { - return g_thread_create_full(func, data, 0, TRUE, TRUE, - G_THREAD_PRIORITY_NORMAL, NULL); + return g_thread_new("coroutine", func, data); } -#endif - - static void __attribute__((constructor)) coroutine_init(void) { if (!g_thread_supported()) { diff --git a/include/glib-compat.h b/include/glib-compat.h index 8d25900..ea965df 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -36,4 +36,17 @@ static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout) } #endif +#if !GLIB_CHECK_VERSION(2, 31, 0) +static inline GThread *g_thread_new(const gchar *unused, + GThreadFunc func, + gpointer data) +{ + GThread *thread = g_thread_create(func, data, TRUE, NULL); + if (!thread) { + g_error("g_thread_create failed"); + } + return thread; +} +#endif + #endif diff --git a/trace/simple.c b/trace/simple.c index 57572c4..8e83e59 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -17,6 +17,7 @@ #include #endif #include "qemu/timer.h" +#include "glib-compat.h" #include "trace.h" #include "trace/control.h" #include "trace/simple.h" @@ -397,11 +398,7 @@ static GThread *trace_thread_create(GThreadFunc fn) pthread_sigmask(SIG_SETMASK, &set, &oldset); #endif -#if GLIB_CHECK_VERSION(2, 31, 0) thread = g_thread_new("trace-thread", fn, NULL); -#else - thread = g_thread_create(fn, NULL, FALSE, NULL); -#endif #ifndef _WIN32 pthread_sigmask(SIG_SETMASK, &oldset, NULL); -- 1.8.5.3