summaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/gc.h8
-rw-r--r--include/private/gc_priv.h4
-rw-r--r--include/private/gcconfig.h13
3 files changed, 19 insertions, 6 deletions
diff --git a/include/gc.h b/include/gc.h
index 7a6da5b..59695b9 100644
--- a/include/gc.h
+++ b/include/gc.h
@@ -344,6 +344,14 @@ GC_API void GC_CALL GC_set_pages_executable(int);
/* use or need synchronization (i.e. acquiring the allocator lock). */
GC_API int GC_CALL GC_get_pages_executable(void);
+/* Overrides the default handle-fork mode. Non-zero value means GC */
+/* should install proper pthread_atfork handlers. Has effect only if */
+/* called before GC_INIT. Clients should invoke GC_set_handle_fork(1) */
+/* only if going to use fork with GC functions called in the forked */
+/* child. (Note that such client and atfork handlers activities are */
+/* not fully POSIX-compliant.) */
+GC_API void GC_CALL GC_set_handle_fork(int);
+
/* Initialize the collector. Portable clients should call GC_INIT() */
/* from the main program instead. */
GC_API void GC_CALL GC_init(void);
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index c49aea4..43e7f26 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -1878,6 +1878,10 @@ GC_EXTERN GC_bool GC_print_back_height;
size_t bytes2);
#endif
+#ifdef CAN_HANDLE_FORK
+ GC_EXTERN GC_bool GC_handle_fork;
+#endif
+
#ifndef GC_DISABLE_INCREMENTAL
GC_EXTERN GC_bool GC_dirty_maintained;
/* Dirty bits are being maintained, */
diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h
index 1cfa835..7ecc80f 100644
--- a/include/private/gcconfig.h
+++ b/include/private/gcconfig.h
@@ -2591,12 +2591,13 @@
# define IF_CANCEL(x) /* empty */
#endif
-#if !defined(HANDLE_FORK) && !defined(NO_HANDLE_FORK) && defined(GC_PTHREADS) \
- && !defined(HURD) && !defined(NACL) && !defined(PLATFORM_ANDROID) \
- && !defined(GC_WIN32_PTHREADS)
- /* Attempts (where supported) to make GC_malloc work in a child */
- /* process fork'ed from a multi-threaded parent. */
-# define HANDLE_FORK
+#if !defined(CAN_HANDLE_FORK) && !defined(NO_HANDLE_FORK) \
+ && ((defined(GC_PTHREADS) && !defined(HURD) && !defined(NACL) \
+ && !defined(PLATFORM_ANDROID) && !defined(GC_WIN32_PTHREADS)) \
+ || defined(HANDLE_FORK))
+ /* Attempts (where supported and requested) to make GC_malloc work in */
+ /* a child process fork'ed from a multi-threaded parent. */
+# define CAN_HANDLE_FORK
#endif
#if !defined(USE_MARK_BITS) && !defined(USE_MARK_BYTES) \