From 686a667317ed5e425bcaecf18d4929911cf1504d Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 29 Mar 2018 01:08:11 +0300 Subject: [PATCH] Enable handle-fork by default Issue #174 (bdwgc). * CMakeLists.txt (enable_handle_fork): New option (on by default). * CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && enable_handle_fork]: Define HANDLE_FORK macro for aix, cygwin, freebsd, haiku, hpux11, irix, kfreebsd, linux, netbsd, openbsd, osf, solaris hosts. * CMakeLists.txt [CMAKE_USE_PTHREADS_INIT && HOST=*-*-darwin* && enable_handle_fork && enable_parallel_mark]: Define HANDLE_FORK macro; add comment. * configure.ac (AC_ARG_ENABLE(handle-fork)): Allow "auto" and "manual" values; update help message. * configure.ac [$enable_handle_fork!=yes && $enable_handle_fork!=no && $enable_handle_fork!=manual && $THREADS=posix]: Define HANDLE_FORK macro for aix, cygwin, freebsd, haiku, hpux11, irix, kfreebsd, linux, netbsd, openbsd, osf, solaris hosts (and also for darwin if enable_parallel_mark); add comment. --- CMakeLists.txt | 13 +++++++++++++ configure.ac | 26 ++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a84b14f9..d4ce7823 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,8 @@ IF(enable_threads) SET(LIBS ${LIBS} ${Threads_LIBRARIES}) ENDIF(enable_threads) +OPTION(enable_handle_fork "Attempt to ensure a usable collector after fork()" ON) + OPTION(enable_thread_local_alloc "Turn on thread-local allocation optimization" ON) OPTION(enable_parallel_mark "Parallelize marking and free list construction" ON) @@ -104,10 +106,21 @@ IF(CMAKE_USE_PTHREADS_INIT) MESSAGE("Only on NetBSD 2.0 or later.") ADD_DEFINITIONS("-D_PTHREADS") ENDIF() + IF( HOST MATCHES .*-.*-aix.*|.*-.*-cygwin.*|.*-.*-.*freebsd.*|.*-.*-haiku.*|.*-.*-hpux11.*|.*-.*-irix.*|.*-.*-kfreebsd.*-gnu|.*-.*-.*linux.*|.*-.*-netbsd.*|.*-.*-openbsd.*|.*-.*-osf.*|.*-.*-solaris.*) + IF(enable_handle_fork) + ADD_DEFINITIONS("-DHANDLE_FORK") + ENDIF(enable_handle_fork) + ENDIF() IF ( HOST MATCHES .*-.*-cygwin.*) SET(SRC ${SRC} win32_threads.c) ENDIF() IF ( HOST MATCHES .*-.*-darwin.*) + IF(enable_handle_fork) + # The incremental mode conflicts with fork handling. + IF(enable_parallel_mark) + ADD_DEFINITIONS("-DHANDLE_FORK") + ENDIF(enable_parallel_mark) + ENDIF(enable_handle_fork) SET(SRC ${SRC} darwin_stop_world.c) #TODO #darwin_threads=true diff --git a/configure.ac b/configure.ac index b7268e65..cfe987a5 100644 --- a/configure.ac +++ b/configure.ac @@ -844,16 +844,34 @@ if test "${enable_large_config}" = yes; then fi AC_ARG_ENABLE(handle-fork, - [AC_HELP_STRING([--enable-handle-fork], - [Attempt to ensure a usable collector after fork() in multi-threaded - programs.])]) - + [AC_HELP_STRING([--enable-handle-fork[=yes|no|auto|manual]], + [Attempt to ensure a usable collector after fork() + in multi-threaded programs (default: auto; + manual: GC_atfork_prepare/parent/child should be + called by the client)])]) if test "${enable_handle_fork}" = yes; then AC_DEFINE(HANDLE_FORK, 1, [Define to install pthread_atfork() handlers by default.]) elif test "${enable_handle_fork}" = no; then AC_DEFINE(NO_HANDLE_FORK, 1, [Prohibit installation of pthread_atfork() handlers.]) +elif test "${enable_handle_fork}" != manual -a x$THREADS = xposix; then + # If the option is omitted, pthread_atfork handlers are installed + # by default for the targets where pthread_atfork is known to work. + case "$host" in + *-*-darwin*) + # The incremental mode (which is off if parallel marking) conflicts + # with fork handling on Darwin. + if test "${enable_parallel_mark}" != no; then + AC_DEFINE(HANDLE_FORK) + fi + ;; + *-*-aix* | *-*-cygwin* | *-*-*freebsd* | *-*-haiku* | \ + *-*-hpux11* | *-*-irix* | *-*-kfreebsd*-gnu | \ + *-*-*linux* | *-*-netbsd* | *-*-openbsd* | *-*-osf* | *-*-solaris*) + AC_DEFINE(HANDLE_FORK) + ;; + esac fi dnl This is something of a hack. When cross-compiling we turn off -- 2.40.0