diff options
author | Ian Rogers <irogers@google.com> | 2012-09-05 07:41:31 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-09-05 07:41:32 -0700 |
commit | 82978cae4eec238a9d631d2b61b8985daa02516e (patch) | |
tree | c36a0ec576cfeb799d855a1c96e3c772f113f946 /libc/upstream-dlmalloc | |
parent | be19a3671709879ccc0156b94f7ef7540027dc37 (diff) | |
parent | 3e2d2936b0447ed2f0b0aab3625494b2533cd422 (diff) | |
download | bionic-82978cae4eec238a9d631d2b61b8985daa02516e.zip bionic-82978cae4eec238a9d631d2b61b8985daa02516e.tar.gz bionic-82978cae4eec238a9d631d2b61b8985daa02516e.tar.bz2 |
Merge "Avoid malloc lock while calling pthread_atfork."
Diffstat (limited to 'libc/upstream-dlmalloc')
-rw-r--r-- | libc/upstream-dlmalloc/malloc.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/libc/upstream-dlmalloc/malloc.c b/libc/upstream-dlmalloc/malloc.c index 0a1f6b2..d951841 100644 --- a/libc/upstream-dlmalloc/malloc.c +++ b/libc/upstream-dlmalloc/malloc.c @@ -3099,6 +3099,9 @@ static void post_fork_child(void) { INITIAL_LOCK(&(gm)->mutex); } /* Initialize mparams */ 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 if (malloc_global_mutex_status <= 0) init_malloc_global_mutex(); @@ -3109,6 +3112,9 @@ static int init_mparams(void) { size_t magic; size_t psize; size_t gsize; + /* BEGIN android-added: move pthread_atfork outside of lock */ + first_run = 1; + /* END android-added */ #ifndef WIN32 psize = malloc_getpagesize; @@ -3153,9 +3159,11 @@ static int init_mparams(void) { gm->mflags = mparams.default_mflags; (void)INITIAL_LOCK(&gm->mutex); #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); #endif + /* END android-removed */ { #if USE_DEV_RANDOM @@ -3184,6 +3192,13 @@ static int init_mparams(void) { } 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; } |