[m-rev.] diff: Support winpthreads

Peter Wang novalazy at gmail.com
Thu Oct 8 13:43:01 AEDT 2015


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.

(backported from bdwgc commit 94b85eea2e2713c7a6071f1965b1e98e645e65a7)
---
 configure.ac               |  5 +++--
 doc/README.macros          |  6 +++---
 doc/README.win32           |  7 ++++---
 include/gc_config_macros.h |  2 +-
 include/private/gc_locks.h |  9 ++++++++-
 win32_threads.c            | 17 ++++++++++-------
 6 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/configure.ac b/configure.ac
index ec0ca23..43f096d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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 win32-pthreads.])
+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 win32-pthreads
+        # Using pthreads-win32 (or other non-Cygwin pthreads) library.
         if test "${enable_parallel_mark}" != no; then
           AC_DEFINE(PARALLEL_MARK)
         fi
diff --git a/doc/README.macros b/doc/README.macros
index d2fef9a..1b36d36 100644
--- a/doc/README.macros
+++ b/doc/README.macros
@@ -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 Ming32 pthreads.  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.
diff --git a/doc/README.win32 b/doc/README.win32
index 5c30d89..0a32c20 100644
--- a/doc/README.win32
+++ b/doc/README.win32
@@ -217,6 +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 Mingw32 Pthreads, use Makefile.direct and
-explicitly set GC_WIN32_PTHREADS.  Use -DPTW32_STATIC_LIB for the static
-threads library.
+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.
diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h
index 9285ddb..d6da7ca 100644
--- a/include/gc_config_macros.h
+++ b/include/gc_config_macros.h
@@ -58,7 +58,7 @@
 #endif
 
 #if defined(GC_WIN32_PTHREADS) && !defined(GC_WIN32_THREADS)
-  /* Using pthreads-w32 library. */
+  /* Using pthreads-win32 library (or other Win32 implementation).  */
 # define GC_WIN32_THREADS
 #endif
 
diff --git a/include/private/gc_locks.h b/include/private/gc_locks.h
index 328d13c..bce48e3 100644
--- a/include/private/gc_locks.h
+++ b/include/private/gc_locks.h
@@ -91,7 +91,14 @@
 #      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 win32-pthread library.   */
        /* Faster than pthread_equal(). Should not change with           */
diff --git a/win32_threads.c b/win32_threads.c
index bfaca35..80c1fde 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -616,7 +616,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             */
@@ -2456,12 +2461,10 @@ GC_INNER void GC_thr_init(void)
 #   ifndef GC_WIN32_PTHREADS
       while ((t = GC_lookup_pthread(pthread_id)) == 0)
         Sleep(10);
-#   endif
-
-    result = pthread_join(pthread_id, retval);
-
-#   ifdef GC_WIN32_PTHREADS
-      /* win32_pthreads id are unique */
+      result = pthread_join(pthread_id, retval);
+#   else
+      result = pthread_join(pthread_id, retval);
+      /* pthreads-win32 and winpthreads id are unique (not recycled). */
       t = GC_lookup_pthread(pthread_id);
       if (NULL == t) ABORT("Thread not registered");
 #   endif
-- 
2.1.2




More information about the reviews mailing list