From 5158253c974afc654e283683af86488e92629900 Mon Sep 17 00:00:00 2001 From: jb Date: Wed, 4 Jun 1997 12:55:49 +0000 Subject: Fix mutex initialization. Malloc cannot use pthread_mutex_init() to initialize a mutex because the mutex initialization process does a malloc! libc_r internals skip the malloc and assign an initializer to a static structure and point the opaque type (pthread_mutex_t in this case) to that structure. This is done on the assumption that the mutex will never be destroyed. This style of initialization is only valid inside libc_r because the structure that is assigned is opaque to the user. This fix allows a simple program to get to main() again. 8-) --- lib/libc/stdlib/malloc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/libc/stdlib/malloc.c') diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index f8f285c..0327517 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: malloc.c,v 1.22 1997/03/18 07:54:24 phk Exp $ + * $Id: malloc.c,v 1.23 1997/05/30 20:39:32 phk Exp $ * */ @@ -72,14 +72,14 @@ #ifdef _THREAD_SAFE #include -static pthread_mutex_t malloc_lock; +#include "pthread_private.h" +static struct pthread_mutex _malloc_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t malloc_lock = &_malloc_lock; #define THREAD_LOCK() pthread_mutex_lock(&malloc_lock) #define THREAD_UNLOCK() pthread_mutex_unlock(&malloc_lock) -#define THREAD_LOCK_INIT() pthread_mutex_init(&malloc_lock, 0); #else #define THREAD_LOCK() #define THREAD_UNLOCK() -#define THREAD_LOCK_INIT() #endif /* @@ -454,8 +454,6 @@ malloc_init () char *p, b[64]; int i, j; - THREAD_LOCK_INIT(); - INIT_MMAP(); #ifdef EXTRA_SANITY -- cgit v1.1