dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0110-do-not-call-g_thread_init-for-glib-2.31.patch

0410ae
From 6b1371a666af982f2d6c0b7dba98c425ea56d3dd Mon Sep 17 00:00:00 2001
0410ae
From: Michael Tokarev <mjt@tls.msk.ru>
0410ae
Date: Fri, 2 May 2014 18:35:55 +0400
0410ae
Subject: [PATCH] do not call g_thread_init() for glib >= 2.31
0410ae
0410ae
glib >= 2.31 always enables thread support and g_thread_supported()
0410ae
is #defined to 1, there's no need to call g_thread_init() anymore,
0410ae
and it definitely does not need to report error which never happens.
0410ae
Keep code for old < 2.31 glibc anyway for now, just #ifdef it
0410ae
differently.
0410ae
0410ae
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
0410ae
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
0410ae
Cc: qemu-trivial@nongnu.org
0410ae
(cherry picked from commit f33cc84dd4af7776309d118412df008ec4108a57)
0410ae
---
0410ae
 coroutine-gthread.c |  7 ++-----
0410ae
 util/osdep.c        | 21 +++++++++------------
0410ae
 2 files changed, 11 insertions(+), 17 deletions(-)
0410ae
0410ae
diff --git a/coroutine-gthread.c b/coroutine-gthread.c
0410ae
index d3e5b99..a61efe0 100644
0410ae
--- a/coroutine-gthread.c
0410ae
+++ b/coroutine-gthread.c
0410ae
@@ -115,14 +115,11 @@ static inline GThread *create_thread(GThreadFunc func, gpointer data)
0410ae
 
0410ae
 static void __attribute__((constructor)) coroutine_init(void)
0410ae
 {
0410ae
-    if (!g_thread_supported()) {
0410ae
 #if !GLIB_CHECK_VERSION(2, 31, 0)
0410ae
+    if (!g_thread_supported()) {
0410ae
         g_thread_init(NULL);
0410ae
-#else
0410ae
-        fprintf(stderr, "glib threading failed to initialize.\n");
0410ae
-        exit(1);
0410ae
-#endif
0410ae
     }
0410ae
+#endif
0410ae
 
0410ae
     init_coroutine_cond();
0410ae
 }
0410ae
diff --git a/util/osdep.c b/util/osdep.c
0410ae
index a9029f8..b2bd154 100644
0410ae
--- a/util/osdep.c
0410ae
+++ b/util/osdep.c
0410ae
@@ -436,23 +436,20 @@ int socket_init(void)
0410ae
     return 0;
0410ae
 }
0410ae
 
0410ae
-/* Ensure that glib is running in multi-threaded mode */
0410ae
+#if !GLIB_CHECK_VERSION(2, 31, 0)
0410ae
+/* Ensure that glib is running in multi-threaded mode
0410ae
+ * Old versions of glib require explicit initialization.  Failure to do
0410ae
+ * this results in the single-threaded code paths being taken inside
0410ae
+ * glib.  For example, the g_slice allocator will not be thread-safe
0410ae
+ * and cause crashes.
0410ae
+ */
0410ae
 static void __attribute__((constructor)) thread_init(void)
0410ae
 {
0410ae
     if (!g_thread_supported()) {
0410ae
-#if !GLIB_CHECK_VERSION(2, 31, 0)
0410ae
-        /* Old versions of glib require explicit initialization.  Failure to do
0410ae
-         * this results in the single-threaded code paths being taken inside
0410ae
-         * glib.  For example, the g_slice allocator will not be thread-safe
0410ae
-         * and cause crashes.
0410ae
-         */
0410ae
-        g_thread_init(NULL);
0410ae
-#else
0410ae
-        fprintf(stderr, "glib threading failed to initialize.\n");
0410ae
-        exit(1);
0410ae
-#endif
0410ae
+       g_thread_init(NULL);
0410ae
     }
0410ae
 }
0410ae
+#endif
0410ae
 
0410ae
 #ifndef CONFIG_IOVEC
0410ae
 /* helper function for iov_send_recv() */