diff options
author | jb <jb@FreeBSD.org> | 1997-06-04 12:55:49 +0000 |
---|---|---|
committer | jb <jb@FreeBSD.org> | 1997-06-04 12:55:49 +0000 |
commit | 5158253c974afc654e283683af86488e92629900 (patch) | |
tree | 66662ae6a7a7d33c393639b6105433b9b6f73815 /lib/libc/stdlib/malloc.c | |
parent | ce34d8d1b14bb396374752c238c0fa458f6b337f (diff) | |
download | FreeBSD-src-5158253c974afc654e283683af86488e92629900.zip FreeBSD-src-5158253c974afc654e283683af86488e92629900.tar.gz |
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-)
Diffstat (limited to 'lib/libc/stdlib/malloc.c')
-rw-r--r-- | lib/libc/stdlib/malloc.c | 10 |
1 files changed, 4 insertions, 6 deletions
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 <pthread.h> -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 |