Re: Proposal: Enable threads by default
- From: Alexander Larsson <alexl redhat com>
- To: Alexander Larsson <alexl redhat com>
- Cc: "gtk-devel-list gnome org" <gtk-devel-list gnome org>
- Subject: Re: Proposal: Enable threads by default
- Date: Tue, 01 Dec 2009 14:29:33 +0100
On Thu, 2009-11-26 at 14:35 +0100, Alexander Larsson wrote:
> This was previously discussed here, but was sort of hidden in a
> technical discussion so it got no replies. I'm starting over in order
> to
> reach a wider target for the discussion.
>
> I'll start with the proposal and then explain the reasons for it:
>
> Starting with next glib release:
> * libgobject links to libgthread
> * g_type_init() starts with:
>
> #ifdef G_THREADS_ENABLED
> if (g_thread_supported())
> g_thread_init (NULL);
> #endif
>
> This means that everything above gobject can rely on thread primitives
> being availible, and that global stuff in glib (mainloop, gslice,
> globals, etc) are threadsafe.
I'm attaching a patch that implements this.
In addition to enabling threads (if complied in) in g_type_init() it
adds a G_THREADS_MANDATORY define that if set causes all the
g_thread_supported() calls to be removed in the g_thread_* macros.
We then pass -DG_THREADS_MANDATORY in gobject and gio if threads are
enabled, letting us avoid a bunch of checks of the
g_threads_got_initialized global variable. I'm not sure how important
this is, but it got rid of 2186 bytes of code in libgobject.so, and it
just seems wrong to constantly check this when its always true.
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Alexander Larsson Red Hat, Inc
alexl redhat com alexander larsson gmail com
He's an immortal pirate gangster from the 'hood. She's an orphaned
nymphomaniac detective on the trail of a serial killer. They fight crime!
diff --git a/configure.in b/configure.in
index 723311f..9b4510b 100644
--- a/configure.in
+++ b/configure.in
@@ -2349,6 +2349,7 @@ case $host in
;;
esac
+AM_CONDITIONAL(HAVE_THREADS, [test "$have_threads" != "none"])
AC_DEFINE_UNQUOTED(G_THREAD_SOURCE,"gthread-$have_threads.c",
[Source file containing theread implementation])
AC_SUBST(G_THREAD_CFLAGS)
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 9dc2e02..62350cb 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -41,6 +41,10 @@ TESTS = abicheck.sh pltcheck.sh
endif
endif
+if HAVE_THREADS
+THREAD_FLAGS=-DG_THREADS_MANDATORY
+endif
+
AM_CPPFLAGS = \
-DG_LOG_DOMAIN=\"GLib-GIO\" \
-I$(top_builddir) \
@@ -48,6 +52,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/glib \
-I$(top_srcdir)/gmodule \
$(GLIB_DEBUG_FLAGS) \
+ $(THREAD_FLAGS) \
-DG_DISABLE_DEPRECATED \
-DGIO_COMPILATION \
-DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\"
diff --git a/glib/gthread.h b/glib/gthread.h
index 019d0db..7a0abba 100644
--- a/glib/gthread.h
+++ b/glib/gthread.h
@@ -198,7 +198,11 @@ GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
(cond, mutex, abs_time, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : TRUE)
#endif /* G_ERRORCHECK_MUTEXES */
+#if defined(G_THREADS_ENABLED) && defined(G_THREADS_MANDATORY)
+#define g_thread_supported() 1
+#else
#define g_thread_supported() (g_threads_got_initialized)
+#endif
#define g_mutex_new() G_THREAD_UF (mutex_new, ())
#define g_cond_new() G_THREAD_UF (cond_new, ())
#define g_cond_signal(cond) G_THREAD_CF (cond_signal, (void)0, (cond))
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..7579dc9 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -6,12 +6,17 @@ include $(top_srcdir)/Makefile.decl
SUBDIRS = . tests
+if HAVE_THREADS
+THREAD_FLAGS=-DG_THREADS_MANDATORY
+endif
+
AM_CPPFLAGS = \
-DG_LOG_DOMAIN=\"GLib-GObject\" \
-I$(top_srcdir) \
-I$(top_srcdir)/glib \
-I$(top_builddir) \
$(GLIB_DEBUG_FLAGS) \
+ $(THREAD_FLAGS) \
-DG_DISABLE_DEPRECATED \
-DGOBJECT_COMPILATION \
-DG_DISABLE_CONST_RETURNS
@@ -31,7 +36,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 cc3b9df..0d816b7 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]