Move the GThread implementations to glib/
authorRyan Lortie <desrt@desrt.ca>
Wed, 31 Aug 2011 22:00:03 +0000 (18:00 -0400)
committerRyan Lortie <desrt@desrt.ca>
Fri, 9 Sep 2011 16:47:40 +0000 (12:47 -0400)
We can now get threads initialised from inside of libglib by calling
g_thread_init_glib().

glib/Makefile.am
glib/gthread-posix.c [moved from gthread/gthread-posix.c with 98% similarity]
glib/gthread-win32.c [moved from gthread/gthread-win32.c with 98% similarity]
glib/gthread.c
glib/gthreadprivate.h
gthread/Makefile.am
gthread/gthread-impl.c

index 1703277..d92f0e6 100644 (file)
@@ -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) \
similarity index 98%
rename from gthread/gthread-posix.c
rename to glib/gthread-posix.c
index da580a7..96abcf8 100644 (file)
@@ -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"
similarity index 98%
rename from gthread/gthread-win32.c
rename to glib/gthread-win32.c
index bfd1ef7..d50aee1 100644 (file)
@@ -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"
index 310a493..9fc5254 100644 (file)
@@ -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
    */
index 30357d7..fdd803a 100644 (file)
@@ -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);
index 700f39c..70b6305 100644 (file)
@@ -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) \
index bd7ba79..123faa0 100644 (file)
  * 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 ();
 }