]> granicus.if.org Git - gc/commitdiff
Enable handle-fork by default
authorIvan Maidanski <ivmai@mail.ru>
Wed, 28 Mar 2018 22:08:11 +0000 (01:08 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 28 Mar 2018 22:08:11 +0000 (01:08 +0300)
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
configure.ac

index a84b14f95df88d5e3442caa34638427d1afab214..d4ce7823c39a8bab2b3a66a10a8869be79940965 100644 (file)
@@ -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
index b7268e6522c76eb99b66c349fda9d89ee57a1583..cfe987a57dff2ce02f26a79bb4caef2d5638b592 100644 (file)
@@ -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