From f1fb79481dd9acd242e2feed1003b51f805078c6 Mon Sep 17 00:00:00 2001 From: jb Date: Wed, 29 Apr 1998 09:10:58 +0000 Subject: Replace the threaded locking with spinlock calls for both threaded and non-threaded programs. This makes malloc thread safe for linking with libpthread and kernel threads. Reviewed by: phk --- lib/libc/stdlib/malloc.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'lib/libc/stdlib/malloc.c') diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 0782598..faafa70 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.35 1998/03/09 07:00:38 jb Exp $ + * $Id: malloc.c,v 1.36 1998/04/04 11:01:52 jb Exp $ * */ @@ -50,15 +50,15 @@ # if !defined(__NETBSD_SYSCALLS) # define HAS_UTRACE # endif -# if defined(_THREAD_SAFE) -# include -# include "pthread_private.h" -# define THREAD_STATUS int thread_lock_status; -# define THREAD_LOCK() _thread_kern_sig_block(&thread_lock_status); -# define THREAD_UNLOCK() _thread_kern_sig_unblock(thread_lock_status); - static struct pthread_mutex _malloc_lock = PTHREAD_MUTEX_STATIC_INITIALIZER; - static pthread_mutex_t malloc_lock = &_malloc_lock; -# endif + /* + * Make malloc/free/realloc thread-safe in libc for use with + * kernel threads. + */ +# include "libc_private.h" +# include "spinlock.h" + static long thread_lock = 0; +# define THREAD_LOCK() if (__isthreaded) _spinlock(&thread_lock); +# define THREAD_UNLOCK() if (__isthreaded) _atomic_unlock(&thread_lock); #endif /* __FreeBSD__ */ #if defined(__sparc__) && defined(sun) @@ -160,10 +160,6 @@ struct pgfree { #define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask))) #define ptr2index(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo) -#ifndef THREAD_STATUS -#define THREAD_STATUS -#endif - #ifndef THREAD_LOCK #define THREAD_LOCK() #endif @@ -1059,7 +1055,6 @@ void * malloc(size_t size) { register void *r; - THREAD_STATUS malloc_func = " in malloc():"; THREAD_LOCK(); @@ -1085,8 +1080,6 @@ malloc(size_t size) void free(void *ptr) { - THREAD_STATUS - malloc_func = " in free():"; THREAD_LOCK(); if (malloc_active++) { @@ -1104,7 +1097,6 @@ free(void *ptr) void * realloc(void *ptr, size_t size) { - THREAD_STATUS register void *r; malloc_func = " in realloc():"; -- cgit v1.1