summaryrefslogtreecommitdiff
path: root/win32_threads.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2012-04-02 18:18:12 +0200
committerIvan Maidanski <ivmai@mail.ru>2012-04-03 06:11:06 +0200
commit1555aa8dd31db657c0ad5eed618757157783c2e5 (patch)
treefb25fe4a88a764a58ade41cf7d0a858cdddc0e3c /win32_threads.c
parenta0e3b0d8444fcae8dbe6a4927f5dc626df81e0e9 (diff)
Add public GC_set_handle_fork to control forked child handling support
(Apply commit 1e882b9 from 'master' branch) * include/gc.h (GC_set_handle_fork): New API function. * misc.c (GC_set_handle_fork): Likewise. * include/private/gc_priv.h (GC_handle_fork): New internal variable declaration (only if CAN_HANDLE_FORK). * misc.c (GC_handle_fork): New internal variable (defined only if CAN_HANDLE_FORK); initialize to TRUE if HANDLE_FORK. * include/private/gcconfig.h (HANDLE_FORK): Replace with CAN_HANDLE_FORK. * pthread_support.c (HANDLE_FORK): Likewise. * win32_threads.c (HANDLE_FORK): Likewise. * include/private/gcconfig.h (CAN_HANDLE_FORK): Always define macro if HANDLE_FORK. * pthread_support.c (GC_thr_init): Replace HANDLE_FORK with CAN_HANDLE_FORK; call pthread_atfork only if GC_handle_fork; update the comment. * win32_threads.c (GC_thr_init): Likewise. * tests/test.c (NO_TEST_HANDLE_FORK): Define new macro if fork handling is not supported (or is a no-op) on the target. * tests/test.c (INIT_FORK_SUPPORT): New macro (invoke GC_set_handle_fork unless NO_TEST_HANDLE_FORK). * tests/test.c (GC_OPT_INIT): New macro (defined to GC_INIT or empty). * tests/test.c (GC_COND_INIT): Use INIT_FORK_SUPPORT and GC_OPT_INIT. * tests/test.c (run_one_test): Test NO_TEST_HANDLE_FORK (instead of target-specific macros). * win32_threads.c (GC_remove_all_threads_but_me, GC_fork_prepare_proc, GC_fork_parent_proc, GC_fork_child_proc): Do not test GC_PTHREADS. * configure.ac (HANDLE_FORK, NO_HANDLE_FORK): Update message.
Diffstat (limited to 'win32_threads.c')
-rw-r--r--win32_threads.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/win32_threads.c b/win32_threads.c
index 0d8d3a7..4017b50 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -55,7 +55,7 @@
STATIC void GC_thread_exit_proc(void *arg);
# include <pthread.h>
-# ifdef HANDLE_FORK
+# ifdef CAN_HANDLE_FORK
# include <unistd.h>
# endif
@@ -974,7 +974,9 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn,
}
}
-# ifdef HANDLE_FORK
+#endif /* GC_PTHREADS */
+
+#ifdef CAN_HANDLE_FORK
/* Similar to that in pthread_support.c but also rehashes the table */
/* since hash map key (thread_id) differs from that in the parent. */
STATIC void GC_remove_all_threads_but_me(void)
@@ -1067,9 +1069,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn,
GC_remove_all_threads_but_me();
UNLOCK();
}
-# endif /* HANDLE_FORK */
-
-#endif /* GC_PTHREADS */
+#endif /* CAN_HANDLE_FORK */
void GC_push_thread_structures(void)
{
@@ -2374,10 +2374,11 @@ GC_INNER void GC_thr_init(void)
GC_main_thread = GetCurrentThreadId();
GC_thr_initialized = TRUE;
-# if defined(GC_PTHREADS) && defined(HANDLE_FORK)
- /* Prepare for a possible fork. */
- if (pthread_atfork(GC_fork_prepare_proc, GC_fork_parent_proc,
- GC_fork_child_proc) != 0)
+# ifdef CAN_HANDLE_FORK
+ /* Prepare for forks if requested. */
+ if (GC_handle_fork
+ && pthread_atfork(GC_fork_prepare_proc, GC_fork_parent_proc,
+ GC_fork_child_proc) != 0)
ABORT("pthread_atfork failed");
# endif