Merge "Avoid malloc lock while calling pthread_atfork."

This commit is contained in:
Ian Rogers
2012-09-05 07:41:31 -07:00
committed by android code review
2 changed files with 17 additions and 1 deletions

View File

@@ -24,6 +24,7 @@
#define REALLOC_ZERO_BYTES_FREES 1 #define REALLOC_ZERO_BYTES_FREES 1
#define USE_DL_PREFIX 1 #define USE_DL_PREFIX 1
#define USE_LOCKS 1 #define USE_LOCKS 1
#define LOCK_AT_FORK 1
#define USE_RECURSIVE_LOCK 0 #define USE_RECURSIVE_LOCK 0
#define USE_SPIN_LOCKS 0 #define USE_SPIN_LOCKS 0

View File

@@ -3099,6 +3099,9 @@ static void post_fork_child(void) { INITIAL_LOCK(&(gm)->mutex); }
/* Initialize mparams */ /* Initialize mparams */
static int init_mparams(void) { static int init_mparams(void) {
/* BEGIN android-added: move pthread_atfork outside of lock */
int first_run = 0;
/* END android-added */
#ifdef NEED_GLOBAL_LOCK_INIT #ifdef NEED_GLOBAL_LOCK_INIT
if (malloc_global_mutex_status <= 0) if (malloc_global_mutex_status <= 0)
init_malloc_global_mutex(); init_malloc_global_mutex();
@@ -3109,6 +3112,9 @@ static int init_mparams(void) {
size_t magic; size_t magic;
size_t psize; size_t psize;
size_t gsize; size_t gsize;
/* BEGIN android-added: move pthread_atfork outside of lock */
first_run = 1;
/* END android-added */
#ifndef WIN32 #ifndef WIN32
psize = malloc_getpagesize; psize = malloc_getpagesize;
@@ -3153,9 +3159,11 @@ static int init_mparams(void) {
gm->mflags = mparams.default_mflags; gm->mflags = mparams.default_mflags;
(void)INITIAL_LOCK(&gm->mutex); (void)INITIAL_LOCK(&gm->mutex);
#endif #endif
#if LOCK_AT_FORK /* BEGIN android-removed: move pthread_atfork outside of lock */
#if 0 && LOCK_AT_FORK
pthread_atfork(&pre_fork, &post_fork_parent, &post_fork_child); pthread_atfork(&pre_fork, &post_fork_parent, &post_fork_child);
#endif #endif
/* END android-removed */
{ {
#if USE_DEV_RANDOM #if USE_DEV_RANDOM
@@ -3184,6 +3192,13 @@ static int init_mparams(void) {
} }
RELEASE_MALLOC_GLOBAL_LOCK(); RELEASE_MALLOC_GLOBAL_LOCK();
/* BEGIN android-added: move pthread_atfork outside of lock */
#if LOCK_AT_FORK
if (first_run != 0) {
pthread_atfork(&pre_fork, &post_fork_parent, &post_fork_child);
}
#endif
/* END android-added */
return 1; return 1;
} }