[glib] Enable threads in g_type_init()



commit fa2bced1f30f93443ef43ce8b5b1e437cd07168c
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Jan 12 21:22:45 2010 +0100

    Enable threads in g_type_init()
    
    This means threads will be supported for all gobject libraries/applications
    and initialized early enough to not cause any problems.
    
    This solves the problem of libraries needing threadsafety. Previosly
    they just called g_threads_init() anyway, which often works but sometimes
    breaks in unexpected ways.
    
    See this thread for more details:
    http://mail.gnome.org/archives/gtk-devel-list/2009-November/msg00208.html
    
    https://bugzilla.gnome.org/show_bug.cgi?id=606775

 docs/reference/glib/tmpl/threads.sgml |    8 ++++++++
 gobject-2.0-uninstalled.pc.in         |    2 +-
 gobject-2.0.pc.in                     |    2 +-
 gobject/Makefile.am                   |    2 +-
 gobject/gtype.c                       |    9 ++++++++-
 5 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/glib/tmpl/threads.sgml b/docs/reference/glib/tmpl/threads.sgml
index baf79a1..feb9399 100644
--- a/docs/reference/glib/tmpl/threads.sgml
+++ b/docs/reference/glib/tmpl/threads.sgml
@@ -49,6 +49,14 @@ threads, so doing this should be avoided if possible.
 </para>
 
 <para>
+Please note that since version 2.24 the GObject initialization
+function g_type_init() initializes threads (with a %NULL argument), so
+most applications, including those using Gtk+ will run with threads
+enabled. If you want a special thread implementation, make sure you
+call g_thread_init() before g_type_init() is called.
+</para>
+
+<para>
 After calling g_thread_init(), GLib is completely
 thread safe (all global data is automatically locked), but individual
 data structure instances are not automatically locked for performance
diff --git a/gobject-2.0-uninstalled.pc.in b/gobject-2.0-uninstalled.pc.in
index 1aab1b5..d9378a5 100644
--- a/gobject-2.0-uninstalled.pc.in
+++ b/gobject-2.0-uninstalled.pc.in
@@ -1,6 +1,6 @@
 Name: GObject Uninstalled
 Description: Object/type system for GLib, Not Installed
-Requires: glib-2.0-uninstalled
+Requires: glib-2.0-uninstalled,gthread-2.0-uninstalled
 Version: @VERSION@
 Libs: ${pc_top_builddir}/${pcfiledir}/gobject/libgobject-2.0.la
 ## cflags contains builddir in addition to srcdir because of gmarshal.h
diff --git a/gobject-2.0.pc.in b/gobject-2.0.pc.in
index 31fe34d..41505a9 100644
--- a/gobject-2.0.pc.in
+++ b/gobject-2.0.pc.in
@@ -5,7 +5,7 @@ includedir= includedir@
 
 Name: GObject
 Description: GLib Type, Object, Parameter and Signal Library
-Requires: glib-2.0
+Requires: glib-2.0,gthread-2.0
 Version: @VERSION@
 Libs: -L${libdir} -lgobject-2.0
 Cflags:
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index b5902d3..98cece3 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -31,7 +31,7 @@ TESTS = abicheck.sh pltcheck.sh
 endif
 endif
 
-libglib = $(top_builddir)/glib/libglib-2.0.la
+libglib = $(top_builddir)/glib/libglib-2.0.la $(top_builddir)/gthread/libgthread-2.0.la
 
 # libraries to compile and install
 lib_LTLIBRARIES = libgobject-2.0.la
diff --git a/gobject/gtype.c b/gobject/gtype.c
index a424bc8..424861e 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -4180,7 +4180,12 @@ g_type_init_with_debug_flags (GTypeDebugFlags debug_flags)
   GTypeInfo info;
   TypeNode *node;
   volatile GType votype;
-  
+
+#ifdef G_THREADS_ENABLED
+  if (!g_thread_get_initialized())
+    g_thread_init (NULL);
+#endif
+
   G_LOCK (type_init_lock);
   
   G_WRITE_LOCK (&type_rw_lock);
@@ -4284,6 +4289,8 @@ g_type_init_with_debug_flags (GTypeDebugFlags debug_flags)
  * to initialize the type system and assorted other code portions
  * (such as the various fundamental type implementations or the signal
  * system).
+ *
+ * Since version 2.24 this also initializes the thread system
  */
 void
 g_type_init (void)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]