From eb4063467c4ef625c1687b4c158bacf475821363 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Mon, 4 May 1998 13:19:20 +0000 Subject: Update. 1998-05-04 12:40 Ulrich Drepper * malloc/malloc.c (ptmalloc_init_all): New function. Similar to ptmalloc_unlock_all, but re-initializes the mutexes instead. (ptmalloc_init): Use new function in thread_at_fork call. (thread_atfork_static): Likewise. Suggested by Wolfram Gloger and Xavier Leroy. --- malloc/malloc.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'malloc') diff --git a/malloc/malloc.c b/malloc/malloc.c index 3d4933cd7c..4a65f520d7 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1,5 +1,5 @@ /* Malloc implementation for multiple threads without lock contention. - Copyright (C) 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Wolfram Gloger and Doug Lea , 1996. @@ -1579,6 +1579,24 @@ ptmalloc_unlock_all __MALLOC_P((void)) (void)mutex_unlock(&list_lock); } +static void +ptmalloc_init_all __MALLOC_P((void)) +{ + arena *ar_ptr; + +#if defined _LIBC || defined MALLOC_HOOKS + tsd_setspecific(arena_key, save_arena); + __malloc_hook = save_malloc_hook; + __free_hook = save_free_hook; +#endif + for(ar_ptr = &main_arena;;) { + (void)mutex_init(&ar_ptr->mutex); + ar_ptr = ar_ptr->next; + if(ar_ptr == &main_arena) break; + } + (void)mutex_init(&list_lock); +} + /* Initialization routine. */ #if defined(_LIBC) #if 0 @@ -1617,7 +1635,7 @@ ptmalloc_init __MALLOC_P((void)) mutex_init(&list_lock); tsd_key_create(&arena_key, NULL); tsd_setspecific(arena_key, (Void_t *)&main_arena); - thread_atfork(ptmalloc_lock_all, ptmalloc_unlock_all, ptmalloc_unlock_all); + thread_atfork(ptmalloc_lock_all, ptmalloc_unlock_all, ptmalloc_init_all); #endif #if defined _LIBC || defined MALLOC_HOOKS if((s = getenv("MALLOC_TRIM_THRESHOLD_"))) @@ -1644,7 +1662,7 @@ ptmalloc_init __MALLOC_P((void)) /* There are platforms (e.g. Hurd) with a link-time hook mechanism. */ #ifdef thread_atfork_static thread_atfork_static(ptmalloc_lock_all, ptmalloc_unlock_all, \ - ptmalloc_unlock_all) + ptmalloc_init_all) #endif #if defined _LIBC || defined MALLOC_HOOKS -- cgit v1.2.3