Skip to content

Commit 949a27f

Browse files
committed
Add pthread_atfork(3) feature test.
Some versions of Android provide a pthreads library without providing pthread_atfork(), so in practice a separate feature test is necessary for the latter.
1 parent 62f2d84 commit 949a27f

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

configure.ac

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,14 @@ if test "x$abi" != "xpecoff" ; then
13291329
AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
13301330
[AC_SEARCH_LIBS([pthread_create], , ,
13311331
AC_MSG_ERROR([libpthread is missing]))])
1332+
JE_COMPILABLE([pthread_atfork(3)], [
1333+
#include <pthread.h>
1334+
], [
1335+
pthread_atfork((void *)0, (void *)0, (void *)0);
1336+
], [je_cv_pthread_atfork])
1337+
if test "x${je_cv_pthread_atfork}" = "xyes" ; then
1338+
AC_DEFINE([JEMALLOC_HAVE_PTHREAD_ATFORK], [ ])
1339+
fi
13321340
fi
13331341

13341342
CPPFLAGS="$CPPFLAGS -D_REENTRANT"

include/jemalloc/internal/jemalloc_internal_defs.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
*/
8080
#undef JEMALLOC_HAVE_ISSETUGID
8181

82+
/* Defined if pthread_atfork(3) is available. */
83+
#undef JEMALLOC_HAVE_PTHREAD_ATFORK
84+
8285
/*
8386
* Defined if clock_gettime(CLOCK_MONOTONIC_COARSE, ...) is available.
8487
*/

src/jemalloc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,8 +1411,9 @@ malloc_init_hard_recursible(void)
14111411

14121412
ncpus = malloc_ncpus();
14131413

1414-
#if (!defined(JEMALLOC_MUTEX_INIT_CB) && !defined(JEMALLOC_ZONE) \
1415-
&& !defined(_WIN32) && !defined(__native_client__))
1414+
#if (defined(JEMALLOC_HAVE_PTHREAD_ATFORK) && !defined(JEMALLOC_MUTEX_INIT_CB) \
1415+
&& !defined(JEMALLOC_ZONE) && !defined(_WIN32) && \
1416+
!defined(__native_client__))
14161417
/* LinuxThreads' pthread_atfork() allocates. */
14171418
if (pthread_atfork(jemalloc_prefork, jemalloc_postfork_parent,
14181419
jemalloc_postfork_child) != 0) {

0 commit comments

Comments
 (0)