[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/3] glib: add g_thread_new() compat function
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH 2/3] glib: add g_thread_new() compat function |
Date: |
Mon, 3 Feb 2014 14:31:49 +0100 |
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 <address@hidden>
---
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 <pthread.h>
#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