[m-rev.] for review: Support building Boehm GC with Winpthreads.
Peter Wang
novalazy at gmail.com
Wed Aug 13 14:45:27 AEST 2014
Branches: master, 14.01
Winpthreads is a pthreads implementation from the MinGW-w64 project,
different from pthreads-win32. A similar patch to this should make its
way into Boehm GC upstream. As we will not be upgrading Boehm GC on the
14.01 branch, apply this small change to our copy of the library for now.
boehm_gc/include/private/gc_locks.h:
Winpthreads uses scalar thread IDs.
boehm_gc/win32_threads.c:
Winpthread thread IDs should be virtually unique but make the
conservative assumption anyway.
---
boehm_gc/include/private/gc_locks.h | 3 ++-
boehm_gc/win32_threads.c | 7 +++++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/boehm_gc/include/private/gc_locks.h b/boehm_gc/include/private/gc_locks.h
index a5d9c35..c28614a 100644
--- a/boehm_gc/include/private/gc_locks.h
+++ b/boehm_gc/include/private/gc_locks.h
@@ -98,7 +98,8 @@
/* 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)
+ /* Mercury-specific: Winpthreads has numeric thread ids */
+# 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/boehm_gc/win32_threads.c b/boehm_gc/win32_threads.c
index 4017b50..fc42607 100755
--- a/boehm_gc/win32_threads.c
+++ b/boehm_gc/win32_threads.c
@@ -2510,14 +2510,17 @@ 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. */
-# ifndef GC_WIN32_PTHREADS
+ /* 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)
while ((t = GC_lookup_pthread(pthread_id)) == 0)
Sleep(10);
# endif
result = pthread_join(pthread_id, retval);
-# ifdef GC_WIN32_PTHREADS
+# if defined(GC_WIN32_PTHREADS) && !defined(__WINPTHREADS_VERSION_MAJOR)
/* win32_pthreads id are unique */
t = GC_lookup_pthread(pthread_id);
# endif
--
1.8.4
More information about the reviews
mailing list