summaryrefslogtreecommitdiff
path: root/misc.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 /misc.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 'misc.c')
-rw-r--r--misc.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/misc.c b/misc.c
index 9d54567..fac069a 100644
--- a/misc.c
+++ b/misc.c
@@ -151,7 +151,32 @@ STATIC void * GC_CALLBACK GC_default_oom_fn(size_t bytes_requested)
/* All accesses to it should be synchronized to avoid data races. */
GC_oom_func GC_oom_fn = GC_default_oom_fn;
-/* Set things up so that GC_size_map[i] >= granules(i), */
+#ifdef CAN_HANDLE_FORK
+# ifdef HANDLE_FORK
+ GC_INNER GC_bool GC_handle_fork = TRUE;
+ /* The value is examined by GC_thr_init. */
+# else
+ GC_INNER GC_bool GC_handle_fork = FALSE;
+# endif
+#endif /* CAN_HANDLE_FORK */
+
+/* Overrides the default handle-fork mode. Non-zero value means GC */
+/* should install proper pthread_atfork handlers (or abort if not */
+/* supported). Has effect only if called before GC_INIT. */
+/*ARGSUSED*/
+GC_API void GC_CALL GC_set_handle_fork(int value)
+{
+# ifdef CAN_HANDLE_FORK
+ if (!GC_is_initialized)
+ GC_handle_fork = (GC_bool)value;
+# elif defined(THREADS)
+ /* FIXME: Handle Darwin case. */
+ if (!GC_is_initialized && value)
+ ABORT("fork() handling disabled");
+# endif
+}
+
+/* Set things up so that GC_size_map[i] >= granules(i), */
/* but not too much bigger */
/* and so that size_map contains relatively few distinct entries */
/* This was originally stolen from Russ Atkinson's Cedar */