[Gc] Support winpthreads

Peter Wang <[email protected]> Tue, 5 Aug 2014 15:54:49 +1000
Newsgroups gmane.comp.programming.garbage-collection.boehmgc
Message-ID <[email protected]>
Hi,

Here is a preliminary patch to support building with winpthreads.
It overloads GC_WIN32_PTHREADS to mean either pthreads-win32 or
winpthreads.  An alternative might be to add a new symbol
GC_WINPTHREADS?

It seems to be fine but I have not tested it extensively.
Perhaps someone else has come across it already?

Peter

_______________________________________________
bdwgc mailing list
[email protected]
https://lists.opendylan.org/mailman/listinfo/bdwgc
0001-Support-Winpthreads.patch (text/x-diff, 5 KB)
From bfd274adb7487fcca6d4307db43a78aaf0219eee Mon Sep 17 00:00:00 2001
From: Peter Wang <[email protected]>
Date: Tue, 5 Aug 2014 15:14:11 +1000
Subject: [PATCH] Support Winpthreads.

Winpthreads is a different pthread implementation for MinGW-w64.
This patch redefines GC_WIN32_PTHREADS to mean either pthreads-win32 or
winpthreads.
---
 configure.ac               | 4 ++--
 doc/README.macros          | 6 +++---
 doc/README.win32           | 6 +++---
 include/gc_config_macros.h | 2 +-
 include/private/gc_locks.h | 2 +-
 win32_threads.c            | 9 ++++++---
 6 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac
index 32982b0..dcda84a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,7 +145,7 @@ 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 +275,7 @@ case "$THREADS" in
         ;;
      *-*-mingw*)
         AC_DEFINE(GC_WIN32_PTHREADS)
-        # Using win32-pthreads
+        # Using pthreads-win32 or winpthreads
         if test "${enable_parallel_mark}" != no; then
           AC_DEFINE(PARALLEL_MARK)
         fi
diff --git a/doc/README.macros b/doc/README.macros
index 6e381a6..43e7c8f 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 MinGW pthreads-win32 or
+  winpthreads.  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..50fc4b5 100644
--- a/doc/README.win32
+++ b/doc/README.win32
@@ -217,6 +217,6 @@ 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 winpthreads, use
+Makefile.direct and explicitly set GC_WIN32_PTHREADS.
+Use -DPTW32_STATIC_LIB for the static threads library.
diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h
index 3c49fe0..90ef99e 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 or winpthreads library. */
 # define GC_WIN32_THREADS
 #endif
 
diff --git a/include/private/gc_locks.h b/include/private/gc_locks.h
index ba1f900..7f0c5d7 100644
--- a/include/private/gc_locks.h
+++ b/include/private/gc_locks.h
@@ -87,7 +87,7 @@
      /* integers for each thread, though that should be true as much    */
      /* as possible.                                                    */
      /* Refine to exclude platforms on which pthread_t is struct */
-#    if !defined(GC_WIN32_PTHREADS)
+#    if !defined(GC_WIN32_PTHREADS) || defined(__WINPTHREADS_VERSION_MAJOR)
 #      define NUMERIC_THREAD_ID(id) ((unsigned long)(id))
 #      define THREAD_EQUAL(id1, id2) ((id1) == (id2))
 #      define NUMERIC_THREAD_ID_UNIQUE
diff --git a/win32_threads.c b/win32_threads.c
index df11a5e..b8d30d3 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -618,7 +618,9 @@ 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
+# ifndef __WINPTHREADS_VERSION_MAJOR
+#  define GC_PTHREAD_PTRVAL(pthread_id) pthread_id.p
+# endif
 #endif
 
 /* If a thread has been joined, but we have not yet             */
@@ -2467,8 +2469,9 @@ GC_INNER void GC_thr_init(void)
 
     result = pthread_join(pthread_id, retval);
 
-#   ifdef GC_WIN32_PTHREADS
-      /* win32_pthreads id are unique */
+#   if defined(GC_WIN32_PTHREADS) && !defined(__WINPTHREADS_VERSION_MAJOR)
+      /* pthreads-win32 id are unique */
+      /* Don't know about winpthreads. */
       t = GC_lookup_pthread(pthread_id);
       if (NULL == t) ABORT("Thread not registered");
 #   endif
-- 
1.8.4