summaryrefslogtreecommitdiff
path: root/pthread_support.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 /pthread_support.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 'pthread_support.c')
-rw-r--r--pthread_support.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/pthread_support.c b/pthread_support.c
index 26ef6e2..41234ab 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -613,7 +613,7 @@ GC_INNER unsigned char *GC_check_finalizer_nested(void)
}
#endif /* GC_ASSERTIONS && THREAD_LOCAL_ALLOC */
-#ifdef HANDLE_FORK
+#ifdef CAN_HANDLE_FORK
/* Remove all entries from the GC_threads table, except the */
/* one for the current thread. We need to do this in the child */
/* process after a fork(), since only the current thread */
@@ -657,7 +657,7 @@ STATIC void GC_remove_all_threads_but_me(void)
GC_threads[hv] = me;
}
}
-#endif /* HANDLE_FORK */
+#endif /* CAN_HANDLE_FORK */
#ifdef USE_PROC_FOR_LIBRARIES
GC_INNER GC_bool GC_segment_is_thread_stack(ptr_t lo, ptr_t hi)
@@ -823,7 +823,7 @@ STATIC void GC_wait_for_gc_completion(GC_bool wait_for_all)
}
}
-#ifdef HANDLE_FORK
+#ifdef CAN_HANDLE_FORK
/* Procedures called before and after a fork. The goal here is to make */
/* it safe to call GC_malloc() in a forked child. It's unclear that is */
/* attainable, since the single UNIX spec seems to imply that one */
@@ -901,7 +901,7 @@ STATIC void GC_fork_child_proc(void)
RESTORE_CANCEL(fork_cancel_state);
UNLOCK();
}
-#endif /* HANDLE_FORK */
+#endif /* CAN_HANDLE_FORK */
#if defined(GC_DGUX386_THREADS)
/* Return the number of processors, or i<= 0 if it can't be determined. */
@@ -956,10 +956,11 @@ GC_INNER void GC_thr_init(void)
if (GC_thr_initialized) return;
GC_thr_initialized = TRUE;
-# ifdef 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
# ifdef INCLUDE_LINUX_THREAD_DESCR