[glib/wip/glib-next: 16/22] Move the GThread implementations to glib/



commit b9c0f545fa04cc6b7cc941594ea12aa2cea1540c
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Aug 31 18:00:03 2011 -0400

    Move the GThread implementations to glib/
    
    We can now get threads initialised from inside of libglib by calling
    g_thread_init_glib().

 glib/Makefile.am                  |   10 ++++++++--
 {gthread => glib}/gthread-posix.c |    8 +++-----
 {gthread => glib}/gthread-win32.c |   11 +++--------
 glib/gthread.c                    |    4 +++-
 glib/gthreadprivate.h             |    1 +
 gthread/Makefile.am               |    8 +-------
 gthread/gthread-impl.c            |    6 ++++--
 7 files changed, 23 insertions(+), 25 deletions(-)
---
diff --git a/glib/Makefile.am b/glib/Makefile.am
index 1703277..d92f0e6 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -207,7 +207,13 @@ libglib_2_0_la_SOURCES = 	\
 
 if OS_UNIX
 libglib_2_0_la_SOURCES += glib-unix.c
-endif	
+endif
+
+if OS_WIN32
+libglib_2_0_la_SOURCES += gthread-win32.c
+else
+libglib_2_0_la_SOURCES += gthread-posix.c
+endif
 
 EXTRA_libglib_2_0_la_SOURCES = \
 	giounix.c	\
@@ -347,7 +353,7 @@ pcre_lib =
 pcre_inc =
 endif
 
-libglib_2_0_la_LIBADD = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ @PLATFORMDEP@ @ICONV_LIBS@ @G_LIBS_EXTRA@ $(pcre_lib) $(GLIB_RT_LIBS)
+libglib_2_0_la_LIBADD = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ @PLATFORMDEP@ @ICONV_LIBS@ @G_LIBS_EXTRA@ $(pcre_lib) $(GLIB_RT_LIBS) $(G_THREAD_LIBS_EXTRA) $(G_THREAD_LIBS_FOR_GTHREAD)
 libglib_2_0_la_DEPENDENCIES = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ @PLATFORMDEP@ $(glib_win32_res) $(glib_def)
 
 libglib_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
diff --git a/gthread/gthread-posix.c b/glib/gthread-posix.c
similarity index 98%
rename from gthread/gthread-posix.c
rename to glib/gthread-posix.c
index da580a7..96abcf8 100644
--- a/gthread/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -132,8 +132,8 @@ static gulong g_thread_min_stack_size = 0;
 
 #define G_MUTEX_SIZE (sizeof (pthread_mutex_t))
 
-static void
-g_thread_impl_init(void)
+void
+_g_thread_impl_init(void)
 {
 #ifdef _SC_THREAD_STACK_MIN
   g_thread_min_stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), 0);
@@ -381,7 +381,7 @@ g_thread_equal_posix_impl (gpointer thread1, gpointer thread2)
   return (pthread_equal (*(pthread_t*)thread1, *(pthread_t*)thread2) != 0);
 }
 
-static GThreadFunctions g_thread_functions_for_glib_use_default =
+GThreadFunctions g_thread_functions_for_glib_use =
 {
   g_mutex_new_posix_impl,
   (void (*)(GMutex *)) pthread_mutex_lock,
@@ -405,5 +405,3 @@ static GThreadFunctions g_thread_functions_for_glib_use_default =
   g_thread_self_posix_impl,
   g_thread_equal_posix_impl
 };
-
-#include "gthread-impl.c"
diff --git a/gthread/gthread-win32.c b/glib/gthread-win32.c
similarity index 98%
rename from gthread/gthread-win32.c
rename to glib/gthread-win32.c
index bfd1ef7..d50aee1 100644
--- a/gthread/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -70,9 +70,6 @@ static GDestroyNotify g_private_destructors[G_PRIVATE_MAX];
 
 static guint g_private_next = 0;
 
-/* A "forward" declaration of this structure */
-static GThreadFunctions g_thread_functions_for_glib_use_default;
-
 typedef struct _GThreadData GThreadData;
 struct _GThreadData
 {
@@ -516,7 +513,7 @@ g_thread_join_win32_impl (gpointer thread)
   g_free (target);
 }
 
-static GThreadFunctions g_thread_functions_for_glib_use_default =
+GThreadFunctions g_thread_functions_for_glib_use =
 {
   g_mutex_new_win32_impl,           /* mutex */
   g_mutex_lock_win32_impl,
@@ -541,8 +538,8 @@ static GThreadFunctions g_thread_functions_for_glib_use_default =
   NULL                             /* no equal function necessary */
 };
 
-static void
-g_thread_impl_init ()
+void
+_g_thread_impl_init (void)
 {
   static gboolean beenhere = FALSE;
 
@@ -559,5 +556,3 @@ g_thread_impl_init ()
 			 (g_cond_event_tls = TlsAlloc ()));
   InitializeCriticalSection (&g_thread_global_spinlock);
 }
-
-#include "gthread-impl.c"
diff --git a/glib/gthread.c b/glib/gthread.c
index 310a493..9fc5254 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -356,7 +356,7 @@ gboolean g_threads_got_initialized = FALSE;
  *
  * For that reason, all of those macros are documented here.
  */
-GThreadFunctions g_thread_functions_for_glib_use = {
+static GThreadFunctions g_thread_functions_for_glib_use_old = {
 /* GMutex Virtual Functions {{{2 ------------------------------------------ */
 
 /**
@@ -925,6 +925,8 @@ G_LOCK_DEFINE_STATIC (g_thread);
 void
 g_thread_init_glib (void)
 {
+  _g_thread_impl_init ();
+
   /* We let the main thread (the one that calls g_thread_init) inherit
    * the static_private data set before calling g_thread_init
    */
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index 30357d7..fdd803a 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -59,6 +59,7 @@ G_GNUC_INTERNAL void _g_main_thread_init (void);
 G_GNUC_INTERNAL void _g_atomic_thread_init (void);
 G_GNUC_INTERNAL void _g_utils_thread_init (void);
 G_GNUC_INTERNAL void _g_futex_thread_init (void);
+G_GNUC_INTERNAL void _g_thread_impl_init  (void);
 
 #ifdef G_OS_WIN32
 G_GNUC_INTERNAL void _g_win32_thread_init (void);
diff --git a/gthread/Makefile.am b/gthread/Makefile.am
index 700f39c..70b6305 100644
--- a/gthread/Makefile.am
+++ b/gthread/Makefile.am
@@ -13,8 +13,6 @@ AM_CPPFLAGS = 				\
 
 EXTRA_DIST +=				\
 		makefile.msc.in		\
-		gthread-posix.c		\
-		gthread-win32.c		\
 		gthread.def		\
 		gthread.rc.in
 
@@ -66,11 +64,7 @@ gthread_win32_res = gthread-win32-res.o
 gthread_win32_res_ldflag = -Wl,$(gthread_win32_res)
 endif
 
-if OS_WIN32
-libgthread_2_0_la_SOURCES = gthread-win32.c
-else
-libgthread_2_0_la_SOURCES = gthread-posix.c
-endif
+libgthread_2_0_la_SOURCES = gthread-impl.c
 libgthread_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gthread_win32_res_ldflag) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
diff --git a/gthread/gthread-impl.c b/gthread/gthread-impl.c
index bd7ba79..123faa0 100644
--- a/gthread/gthread-impl.c
+++ b/gthread/gthread-impl.c
@@ -31,6 +31,10 @@
  * MT safe
  */
 
+#include "glib.h"
+
+#include "gthreadprivate.h"
+
 void
 g_thread_init (GThreadFunctions *init)
 {
@@ -44,8 +48,6 @@ g_thread_init (GThreadFunctions *init)
 
   already_done = TRUE;
 
-  g_thread_impl_init ();
-  g_thread_functions_for_glib_use = g_thread_functions_for_glib_use_default;
   g_thread_init_glib ();
 }
 



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