qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PATCH 2/3] glib: add g_thread_new() compat function
Date: Mon,  3 Feb 2014 14:31:49 +0100	[thread overview]
Message-ID: <1391434310-9990-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1391434310-9990-1-git-send-email-stefanha@redhat.com>

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(-)

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

  parent reply	other threads:[~2014-02-03 13:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-03 13:31 [Qemu-devel] [PATCH 0/3] glib: move compat functions into glib-compat.h Stefan Hajnoczi
2014-02-03 13:31 ` [Qemu-devel] [PATCH 1/3] glib: move g_poll() replacement " Stefan Hajnoczi
2014-02-03 13:31 ` Stefan Hajnoczi [this message]
2014-02-03 13:31 ` [Qemu-devel] [PATCH 3/3] glib: add compat wrapper for GStaticMutex Stefan Hajnoczi
2014-02-14 12:31 ` [Qemu-devel] [PATCH 0/3] glib: move compat functions into glib-compat.h Stefan Hajnoczi
2014-05-02  9:35 ` Stefan Hajnoczi
  -- strict thread matches above, loose matches on Subject: below --
2014-05-02 10:52 [Qemu-devel] [PATCH 2/3] glib: add g_thread_new() compat function Michael Tokarev
2014-05-02 11:01 ` Daniel P. Berrange
2014-05-02 11:08   ` Peter Maydell
2014-05-02 11:16     ` Michael Tokarev
2014-05-02 12:30     ` Michael Tokarev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1391434310-9990-3-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).