diff --git a/configure.ac b/configure.ac index a00aab9b..32ae02c2 100644 --- a/configure.ac +++ b/configure.ac @@ -1452,6 +1452,7 @@ if test "x$abi" != "xpecoff" ; then [AC_SEARCH_LIBS([pthread_create], , , AC_MSG_ERROR([libpthread is missing]))]) wrap_syms="${wrap_syms} pthread_create" + have_pthread="1" dnl Check if we have dlsym support. have_dlsym="1" AC_CHECK_HEADERS([dlfcn.h], @@ -1933,6 +1934,15 @@ if test "x${enable_zone_allocator}" = "x1" ; then AC_DEFINE([JEMALLOC_ZONE], [ ]) fi +dnl ============================================================================ +dnl Enable background threads if possible. + +if test "x${have_pthread}" = "x1" -a "x${have_dlsym}" = "x1" \ + -a "x${je_cv_os_unfair_lock}" != "xyes" \ + -a "x${je_cv_osspin}" != "xyes" ; then + AC_DEFINE([JEMALLOC_BACKGROUND_THREAD]) +fi + dnl ============================================================================ dnl Check for glibc malloc hooks diff --git a/include/jemalloc/internal/jemalloc_internal_defs.h.in b/include/jemalloc/internal/jemalloc_internal_defs.h.in index 20a2358e..2bf9dea1 100644 --- a/include/jemalloc/internal/jemalloc_internal_defs.h.in +++ b/include/jemalloc/internal/jemalloc_internal_defs.h.in @@ -316,6 +316,11 @@ /* GNU specific sched_setaffinity support */ #undef JEMALLOC_HAVE_SCHED_SETAFFINITY +/* + * If defined, all the features necessary for background threads are present. + */ +#undef JEMALLOC_BACKGROUND_THREAD + /* * If defined, jemalloc symbols are not exported (doesn't work when * JEMALLOC_PREFIX is not defined). diff --git a/include/jemalloc/internal/jemalloc_preamble.h.in b/include/jemalloc/internal/jemalloc_preamble.h.in index 46750e99..18539a09 100644 --- a/include/jemalloc/internal/jemalloc_preamble.h.in +++ b/include/jemalloc/internal/jemalloc_preamble.h.in @@ -168,12 +168,6 @@ static const bool force_ivsalloc = false #endif ; - -#if (defined(JEMALLOC_HAVE_PTHREAD) && defined(JEMALLOC_HAVE_DLSYM) \ - && !defined(JEMALLOC_OSSPIN) && !defined(JEMALLOC_OS_UNFAIR_LOCK)) -/* Currently background thread supports pthread only. */ -#define JEMALLOC_BACKGROUND_THREAD -#endif static const bool have_background_thread = #ifdef JEMALLOC_BACKGROUND_THREAD true diff --git a/src/background_thread.c b/src/background_thread.c index 190fa2fd..51d23cb9 100644 --- a/src/background_thread.c +++ b/src/background_thread.c @@ -635,7 +635,9 @@ background_thread_stats_read(tsdn_t *tsdn, background_thread_stats_t *stats) { void background_thread_ctl_init(tsdn_t *tsdn) { malloc_mutex_assert_not_owner(tsdn, &background_thread_lock); +#ifdef JEMALLOC_PTHREAD_CREATE_WRAPPER pthread_once(&once_control, pthread_create_wrapper_once); +#endif } #endif /* defined(JEMALLOC_BACKGROUND_THREAD) */