Support winpthreads
authorPeter Wang <novalazy@gmail.com>
Sat, 23 Aug 2014 08:48:37 +0000 (12:48 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 23 Aug 2014 08:48:37 +0000 (12:48 +0400)
Winpthreads is a different pthread implementation for MinGW-w64.
This patch redefines GC_WIN32_PTHREADS to mean either pthreads-win32
or winpthreads.

* configure.ac (GC_WIN32_PTHREADS): Improve description to cover
"winpthreads" library.
* doc/README.macros (GC_WIN32_PTHREADS): Likewise.
* doc/README.win32: Likewise.
* include/gc_config_macros.h (GC_WIN32_THREADS): Mention "winpthreads"
library in comment.
* win32_threads.c (GC_pthread_join): Likewise.
* include/private/gc_locks.h (NUMERIC_THREAD_ID, THREAD_EQUAL,
NUMERIC_THREAD_ID_UNIQUE): Define to support winpthreads properly (if
GC_WIN32_PTHREADS).
* win32_threads.c (GC_PTHREAD_PTRVAL): Likewise.

configure.ac
doc/README.macros
doc/README.win32
include/gc_config_macros.h
include/private/gc_locks.h
win32_threads.c

index fac8edd..45ab693 100644 (file)
@@ -145,7 +145,8 @@ AH_TEMPLATE([GC_OPENBSD_THREADS],   [Define to support OpenBSD pthreads.])
 AH_TEMPLATE([GC_OSF1_THREADS],      [Define to support Tru64 pthreads.])
 AH_TEMPLATE([GC_SOLARIS_THREADS],   [Define to support Solaris pthreads.])
 AH_TEMPLATE([GC_WIN32_THREADS],     [Define to support Win32 threads.])
-AH_TEMPLATE([GC_WIN32_PTHREADS],    [Define to support pthreads-win32.])
+AH_TEMPLATE([GC_WIN32_PTHREADS],
+                [Define to support pthreads-win32 or winpthreads.])
 AH_TEMPLATE([GC_RTEMS_PTHREADS],    [Define to support rtems-pthreads.])
 
 dnl System header feature requests.
@@ -275,7 +276,7 @@ case "$THREADS" in
         ;;
      *-*-mingw*)
         AC_DEFINE(GC_WIN32_PTHREADS)
-        # Using pthreads-win32 library.
+        # Using pthreads-win32 (or other non-Cygwin pthreads) library.
         if test "${enable_parallel_mark}" != no; then
           AC_DEFINE(PARALLEL_MARK)
         fi
index 96a41c7..3cc302e 100644 (file)
@@ -149,9 +149,9 @@ GC_DGUX386_THREADS      Enables support for DB/UX on I386 threads.
 GC_WIN32_THREADS        Enables support for Win32 threads.  That makes sense
   for this Makefile only under Cygwin.
 
-GC_WIN32_PTHREADS       Enables support for pthreads-win32.  This cannot be
-  enabled automatically by GC_THREADS, which would assume Win32 native
-  threads.
+GC_WIN32_PTHREADS       Enables support for pthreads-win32 (or other
+  non-Cygwin pthreads library for Windows).  This cannot be enabled
+  automatically by GC_THREADS, which would assume Win32 native threads.
 
 PTW32_STATIC_LIB        Causes the static version of the Mingw pthreads
   library to be used.  Requires GC_WIN32_PTHREADS.
index 134681c..0a32c20 100644 (file)
@@ -217,7 +217,7 @@ especially with the garbage collector.  Any use is likely to provoke a
 crash in the GC, since it makes it impossible for the collector to
 correctly track threads.
 
-To build the collector for MinGW pthreads-win32,
-use Makefile.direct and explicitly set
+To build the collector for MinGW pthreads-win32 (or other non-Cygwin pthreads
+implementation for Windows), use Makefile.direct and explicitly set
 GC_WIN32_PTHREADS (or pass --enable-threads=pthreads to configure).
 Use -DPTW32_STATIC_LIB for the static threads library.
index ae970e1..db8a40d 100644 (file)
@@ -58,7 +58,7 @@
 #endif
 
 #if defined(GC_WIN32_PTHREADS) && !defined(GC_WIN32_THREADS)
-  /* Using pthreads-win32 library.  */
+  /* Using pthreads-win32 library (or other Win32 implementation).  */
 # define GC_WIN32_THREADS
 #endif
 
index 964182a..6507609 100644 (file)
 #      define NUMERIC_THREAD_ID(id) ((unsigned long)(id))
 #      define THREAD_EQUAL(id1, id2) ((id1) == (id2))
 #      define NUMERIC_THREAD_ID_UNIQUE
-#    else
+#    elif defined(__WINPTHREADS_VERSION_MAJOR) /* winpthreads */
+#      define NUMERIC_THREAD_ID(id) ((unsigned long)(id))
+#      define THREAD_EQUAL(id1, id2) ((id1) == (id2))
+#      ifndef _WIN64
+         /* NUMERIC_THREAD_ID is 32-bit and not unique on Win64. */
+#        define NUMERIC_THREAD_ID_UNIQUE
+#      endif
+#    else /* pthreads-win32 */
 #      define NUMERIC_THREAD_ID(id) ((unsigned long)(id.p))
        /* Using documented internal details of pthreads-win32 library.  */
        /* Faster than pthread_equal(). Should not change with           */
index 2b783f4..fc65743 100644 (file)
@@ -618,7 +618,12 @@ GC_API int GC_CALL GC_thread_is_registered(void)
 #ifdef CYGWIN32
 # define GC_PTHREAD_PTRVAL(pthread_id) pthread_id
 #elif defined(GC_WIN32_PTHREADS) || defined(GC_PTHREADS_PARAMARK)
-# define GC_PTHREAD_PTRVAL(pthread_id) pthread_id.p
+# include <pthread.h> /* to check for winpthreads */
+# if defined(__WINPTHREADS_VERSION_MAJOR)
+#   define GC_PTHREAD_PTRVAL(pthread_id) pthread_id
+# else
+#   define GC_PTHREAD_PTRVAL(pthread_id) pthread_id.p
+# endif
 #endif
 
 /* If a thread has been joined, but we have not yet             */
@@ -2469,7 +2474,7 @@ GC_INNER void GC_thr_init(void)
       result = pthread_join(pthread_id, retval);
 #   else
       result = pthread_join(pthread_id, retval);
-      /* pthreads-win32 id are unique (not recycled) */
+      /* pthreads-win32 and winpthreads id are unique (not recycled). */
       t = GC_lookup_pthread(pthread_id);
       if (NULL == t) ABORT("Thread not registered");
 #   endif