[m-rev.] diff: Backport Boehm GC changes for Winpthreads support.

Peter Wang novalazy at gmail.com
Mon Aug 25 14:35:00 AEST 2014


Make our changes to support Winpthreads match those of upstream
bdwgc commit 94b85eea2e2713c7a6071f1965b1e98e645e65a7

boehm_gc/include/private/gc_locks.h:
boehm_gc/win32_threads.c:
	As above.

diff --git a/boehm_gc/include/private/gc_locks.h b/boehm_gc/include/private/gc_locks.h
index c28614a..8f531fe 100644
--- a/boehm_gc/include/private/gc_locks.h
+++ b/boehm_gc/include/private/gc_locks.h
@@ -98,12 +98,19 @@
      /* integers for each thread, though that should be true as much    */
      /* as possible.                                                    */
      /* Refine to exclude platforms on which pthread_t is struct */
-     /* Mercury-specific: Winpthreads has numeric thread ids */
-#    if !defined(GC_WIN32_PTHREADS) || defined(__WINPTHREADS_VERSION_MAJOR)
+#    if !defined(GC_WIN32_PTHREADS)
 #      define NUMERIC_THREAD_ID(id) ((unsigned long)(id))
 #      define THREAD_EQUAL(id1, id2) ((id1) == (id2))
 #      define NUMERIC_THREAD_ID_UNIQUE
-#    else
+     /* Mercury-specific: backported Winpthreads support */
+#    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/boehm_gc/win32_threads.c b/boehm_gc/win32_threads.c
index fc42607..eee92d3 100755
--- a/boehm_gc/win32_threads.c
+++ b/boehm_gc/win32_threads.c
@@ -602,10 +602,16 @@ GC_INNER unsigned char *GC_check_finalizer_nested(void)
 # define UNPROTECT_THREAD(t)
 #endif
 
+/* Mercury-specific: backported Winpthreads support */
 #ifdef CYGWIN32
 # define GC_PTHREAD_PTRVAL(pthread_id) pthread_id
-#elif defined(GC_WIN32_PTHREADS)
-# define GC_PTHREAD_PTRVAL(pthread_id) pthread_id.p
+#elif defined(GC_WIN32_PTHREADS) || defined(GC_PTHREADS_PARAMARK)
+# 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             */
@@ -2510,19 +2516,16 @@ GC_INNER void GC_thr_init(void)
     /* After the join,thread id may have been recycled.          */
     /* FIXME: It would be better if this worked more like        */
     /* pthread_support.c.                                        */
-    /* Mercury-specific: Winpthreads allocates threads ids       */
-    /* incrementally (with wraparound) so should be practically  */
-    /* unique, but let's make the conservative assumption. --pw  */
-#   if !defined(GC_WIN32_PTHREADS) || defined(__WINPTHREADS_VERSION_MAJOR)
+    /* Mercury-specific: backported Winpthreads support          */
+#   ifndef GC_WIN32_PTHREADS
       while ((t = GC_lookup_pthread(pthread_id)) == 0)
         Sleep(10);
-#   endif
-
-    result = pthread_join(pthread_id, retval);
-
-#   if defined(GC_WIN32_PTHREADS) && !defined(__WINPTHREADS_VERSION_MAJOR)
-      /* 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
 
     if (!GC_win32_dll_threads) {
-- 
1.8.4



More information about the reviews mailing list