Fix threaded initialization and enable it on Linux.
Reported by Mike Hommey.
This commit is contained in:
parent
f3ca7c8386
commit
02b231205e
@ -228,6 +228,7 @@ case "${host}" in
|
|||||||
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
|
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
|
||||||
abi="elf"
|
abi="elf"
|
||||||
AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
|
AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
|
||||||
|
AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
|
||||||
RPATH="-Wl,-rpath,"
|
RPATH="-Wl,-rpath,"
|
||||||
;;
|
;;
|
||||||
*-*-netbsd*)
|
*-*-netbsd*)
|
||||||
|
@ -36,13 +36,15 @@ static bool malloc_initialized = false;
|
|||||||
|
|
||||||
#ifdef JEMALLOC_THREADED_INIT
|
#ifdef JEMALLOC_THREADED_INIT
|
||||||
/* Used to let the initializing thread recursively allocate. */
|
/* Used to let the initializing thread recursively allocate. */
|
||||||
static pthread_t malloc_initializer = (unsigned long)0;
|
# define NO_INITIALIZER ((unsigned long)0)
|
||||||
# define INITIALIZER pthread_self()
|
# define INITIALIZER pthread_self()
|
||||||
# define IS_INITIALIZER (malloc_initializer == pthread_self())
|
# define IS_INITIALIZER (malloc_initializer == pthread_self())
|
||||||
|
static pthread_t malloc_initializer = NO_INITIALIZER;
|
||||||
#else
|
#else
|
||||||
static bool malloc_initializer = false;
|
# define NO_INITIALIZER false
|
||||||
# define INITIALIZER true
|
# define INITIALIZER true
|
||||||
# define IS_INITIALIZER malloc_initializer
|
# define IS_INITIALIZER malloc_initializer
|
||||||
|
static bool malloc_initializer = NO_INITIALIZER;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Used to avoid initialization races. */
|
/* Used to avoid initialization races. */
|
||||||
@ -531,7 +533,7 @@ malloc_init_hard(void)
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
#ifdef JEMALLOC_THREADED_INIT
|
#ifdef JEMALLOC_THREADED_INIT
|
||||||
if (IS_INITIALIZER == false) {
|
if (malloc_initializer != NO_INITIALIZER && IS_INITIALIZER == false) {
|
||||||
/* Busy-wait until the initializing thread completes. */
|
/* Busy-wait until the initializing thread completes. */
|
||||||
do {
|
do {
|
||||||
malloc_mutex_unlock(&init_lock);
|
malloc_mutex_unlock(&init_lock);
|
||||||
|
Loading…
Reference in New Issue
Block a user