Fix extra/gc.c to enable GC source inclusion from multi-threaded app
authorIvan Maidanski <ivmai@mail.ru>
Fri, 13 Jan 2012 15:53:47 +0000 (19:53 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 13 Jan 2012 15:53:47 +0000 (19:53 +0400)
* extra/gc.c: Include gc_pthread_redirects.h (unless
GC_NO_THREAD_REDIRECTS) to restore thread calls macro-based
redirection after the corresponding undef's in pthread_support.c.
* win32_threads.c: Restore thread calls macro-based redirection
(unless GC_NO_THREAD_REDIRECTS) at the file end.
* extra/gc.c: Remove "file not well tested" comment.

extra/gc.c
win32_threads.c

index f48f989..9c16d20 100644 (file)
@@ -27,8 +27,6 @@
 /* for GC and the client otherwise GC_thread_exit_proc() is not         */
 /* guaranteed to be invoked (see the comments in pthread_start.c).      */
 
-/* This file is not well tested (for now). */
-
 
 #define GC_INNER STATIC
 #define GC_EXTERN GC_INNER
 
 #include "../pthread_start.c"
 
+/* Restore pthread calls redirection (if altered in             */
+/* pthread_stop_world.c, pthread_support.c or win32_threads.c). */
+/* This is only useful if directly included from application    */
+/* (instead of linking gc).                                     */
+#ifndef GC_NO_THREAD_REDIRECTS
+# include "gc_pthread_redirects.h"
+#endif
+
 /* real_malloc.c, extra/MacOS.c, extra/msvc_dbg.c are not included. */
index 4bc0cb4..7cc0dcf 100644 (file)
@@ -2758,4 +2758,14 @@ GC_INNER void GC_init_parallel(void)
 
 #endif /* THREAD_LOCAL_ALLOC ... */
 
+# ifndef GC_NO_THREAD_REDIRECTS
+    /* Restore thread calls redirection.        */
+#   define CreateThread GC_CreateThread
+#   define ExitThread GC_ExitThread
+#   undef _beginthreadex
+#   define _beginthreadex GC_beginthreadex
+#   undef _endthreadex
+#   define _endthreadex GC_endthreadex
+# endif /* !GC_NO_THREAD_REDIRECTS */
+
 #endif /* GC_WIN32_THREADS */