From c1f295aa8666eb1c08a1edf944ac5617659a066c Mon Sep 17 00:00:00 2001 From: d <> Date: Fri, 20 Nov 1998 11:18:51 +0000 Subject: Add thread-safety to libc, so that libc_r will build (on i386 at least). All POSIX libc api now there (to P1003.1c/D10) (more md stuff is needed for other libc/arch/*) (setlogin is no longer a special syscall) Add -pthread option to gcc (that makes it use -lc_r and -D_POSIX_THREADS). Doc some re-entrant routines Add libc_r to intro(3) dig() uses some libc srcs and an extra -I was needed there. Add more md stuff to libc_r. Update includes for the pthreads api Update libc_r TODO --- src/lib/libc/stdlib/malloc.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/lib/libc/stdlib/malloc.c') diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index d1d8759791..ecbf93dc48 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c @@ -8,7 +8,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: malloc.c,v 1.32 1998/08/06 16:26:32 millert Exp $"; +static char rcsid[] = "$OpenBSD: malloc.c,v 1.33 1998/11/20 11:18:50 d Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -87,15 +87,27 @@ static char rcsid[] = "$OpenBSD: malloc.c,v 1.32 1998/08/06 16:26:32 millert Exp #endif /* __OpenBSD__ */ #ifdef _THREAD_SAFE -#include -static pthread_mutex_t 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); +# include "thread_private.h" +# if 0 + /* kernel threads */ +# include + static pthread_mutex_t 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 + /* user threads */ +# include "spinlock.h" + static spinlock_t malloc_lock = _SPINLOCK_INITIALIZER; +# define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&malloc_lock) +# define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&malloc_lock) +# define THREAD_LOCK_INIT() +# endif #else -#define THREAD_LOCK() -#define THREAD_UNLOCK() -#define THREAD_LOCK_INIT() + /* no threads */ +# define THREAD_LOCK() +# define THREAD_UNLOCK() +# define THREAD_LOCK_INIT() #endif /* -- cgit v1.2.3-55-g6feb