@@ -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()) {
@@ -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
@@ -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);
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 <stefanha@redhat.com> --- coroutine-gthread.c | 13 +++---------- include/glib-compat.h | 13 +++++++++++++ trace/simple.c | 5 +---- 3 files changed, 17 insertions(+), 14 deletions(-)