win32: Allow POSIX threads to be used if --with-threads=posix
authorРуслан Ижбулатов <lrn1986@gmail.com>
Tue, 9 Apr 2013 12:09:33 +0000 (14:09 +0200)
committerAlexander Larsson <alexl@redhat.com>
Tue, 9 Apr 2013 12:10:13 +0000 (14:10 +0200)
All tests pass with this patch AND a good pthreads implementation
(i'm using winpthreads, not pthreads-w32).

https://bugzilla.gnome.org/show_bug.cgi?id=697626

configure.ac
glib/Makefile.am
glib/glib-init.c
glib/gthread-posix.c

index 73c9d60..55d1c55 100644 (file)
@@ -2177,14 +2177,20 @@ AS_IF([test x$have_threads = xposix], [
          ])
 
          g_threads_impl="POSIX"
+          AC_DEFINE([THREADS_POSIX], [1], [Use pthreads])
          AC_SUBST(GTHREAD_COMPILE_IMPL_DEFINES)
           CPPFLAGS="$glib_save_CPPFLAGS"
 ], [test x$have_threads = xwin32], [
+           AC_DEFINE([THREADS_WIN32], [1], [Use w32 threads])
           g_threads_impl="WIN32"
 ], [
+           AC_DEFINE([THREADS_NONE], [1], [Use no threads])
           g_threads_impl="NONE"
            G_THREAD_LIBS=error
 ])
+AM_CONDITIONAL(THREADS_POSIX, [test "$g_threads_impl" = "POSIX"])
+AM_CONDITIONAL(THREADS_WIN32, [test "$g_threads_impl" = "WIN32"])
+AM_CONDITIONAL(THREADS_NONE, [test "$g_threads_impl" = "NONE"])
 
 if test "x$G_THREAD_LIBS" = xerror; then
         AC_MSG_ERROR($LIBS_NOT_FOUND_1$have_threads$LIBS_NOT_FOUND_2)
index 021a26a..98d91af 100644 (file)
@@ -214,11 +214,13 @@ if OS_UNIX
 libglib_2_0_la_SOURCES += glib-unix.c
 endif
 
-if OS_WIN32
+if THREADS_WIN32
 libglib_2_0_la_SOURCES += gthread-win32.c
 else
+if THREADS_POSIX
 libglib_2_0_la_SOURCES += gthread-posix.c
 endif
+endif
 
 EXTRA_libglib_2_0_la_SOURCES = \
        giounix.c       \
index 49c7f61..0032ee8 100644 (file)
@@ -239,12 +239,16 @@ DllMain (HINSTANCE hinstDLL,
     case DLL_PROCESS_ATTACH:
       glib_dll = hinstDLL;
       g_clock_win32_init ();
+#ifdef THREADS_WIN32
       g_thread_win32_init ();
+#endif
       glib_init ();
       break;
 
     case DLL_THREAD_DETACH:
+#ifdef THREADS_WIN32
       g_thread_win32_thread_detach ();
+#endif
       break;
 
     default:
index e65e437..23371ae 100644 (file)
@@ -66,6 +66,9 @@
 #ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
 #endif
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
 
 static void
 g_thread_abort (gint         status,