summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/malloc.c
diff options
context:
space:
mode:
authorDavid Leonard <d@cvs.openbsd.org>1998-11-20 11:19:02 +0000
committerDavid Leonard <d@cvs.openbsd.org>1998-11-20 11:19:02 +0000
commitf547068f88348f54941dc06da46491f99701933e (patch)
tree8548a6b78719cba1de575b7f49e5f8ac4e6f1683 /lib/libc/stdlib/malloc.c
parent394c7a9821726b84f284c0c4385b1a9198afa0b0 (diff)
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
Diffstat (limited to 'lib/libc/stdlib/malloc.c')
-rw-r--r--lib/libc/stdlib/malloc.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index d1d87597918..ecbf93dc489 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/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 <pthread.h>
-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 <pthread.h>
+ 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
/*