diff options
author | Marco S Hyman <marc@cvs.openbsd.org> | 2002-11-05 22:19:57 +0000 |
---|---|---|
committer | Marco S Hyman <marc@cvs.openbsd.org> | 2002-11-05 22:19:57 +0000 |
commit | 18f91d47d9735c52e8c411d33ddfd95db158838b (patch) | |
tree | cb9f8328e35c7aa89eff800e8104ac42f6f06526 | |
parent | adc2ae85730a0252b7aa8c29f3bb73a13e81ea76 (diff) |
thread safe libc -- 2nd try. OK miod@, millert@
Thanks to miod@ for m68k and vax fixes
-rw-r--r-- | lib/libc/arch/m68k/SYS.h | 37 | ||||
-rw-r--r-- | lib/libc/arch/vax/SYS.h | 38 | ||||
-rw-r--r-- | lib/libc/include/thread_private.h | 70 | ||||
-rw-r--r-- | lib/libc/stdlib/abort.c | 10 | ||||
-rw-r--r-- | lib/libc/stdlib/malloc.c | 57 | ||||
-rw-r--r-- | lib/libc/sys/Makefile.inc | 7 | ||||
-rw-r--r-- | lib/libc/thread/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/thread/thread_fd.c | 37 | ||||
-rw-r--r-- | lib/libc/thread/unithread_malloc_lock.c | 16 | ||||
-rw-r--r-- | lib/libc_r/thread/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc_r/thread/thread_malloc_lock.c | 10 | ||||
-rw-r--r-- | lib/libc_r/thread/thread_storage.c | 6 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_fd.c | 41 | ||||
-rw-r--r-- | lib/libpthread/thread/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libpthread/thread/thread_malloc_lock.c | 10 | ||||
-rw-r--r-- | lib/libpthread/thread/thread_storage.c | 6 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_fd.c | 41 |
17 files changed, 155 insertions, 243 deletions
diff --git a/lib/libc/arch/m68k/SYS.h b/lib/libc/arch/m68k/SYS.h index 6708c564600..2c5cd215982 100644 --- a/lib/libc/arch/m68k/SYS.h +++ b/lib/libc/arch/m68k/SYS.h @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: SYS.h,v 1.12 2002/11/05 00:02:17 miod Exp $ + * $OpenBSD: SYS.h,v 1.13 2002/11/05 22:19:55 marc Exp $ */ #include <sys/syscall.h> @@ -83,27 +83,28 @@ rts -#ifdef _THREAD_SAFE +#ifdef __STDC__ +#define __ALIAS(prefix,name) \ + WEAK_ALIAS(name,prefix##name); +#else +#define __ALIAS(prefix,name) \ + WEAK_ALIAS(name,prefix/**/name); +#endif + /* * For the thread_safe versions, we prepend _thread_sys_ to the function * name so that the 'C' wrapper can go around the real name. */ -# define SYSCALL(x) __SYSCALL(_thread_sys_,x,x) -# define RSYSCALL(x) __PSEUDO(_thread_sys_,x,x) -# define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) -# define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) -# define SYSENTRY(x) __ENTRY(_thread_sys_,x) -#else /* _THREAD_SAFE */ -/* - * The non-threaded library defaults to traditional syscalls where - * the function name matches the syscall name. - */ -# define SYSCALL(x) __SYSCALL(,x,x) -# define RSYSCALL(x) __PSEUDO(,x,x) -# define PSEUDO(x,y) __PSEUDO(,x,y) -# define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(,x,y) -# define SYSENTRY(x) __ENTRY(,x) -#endif /* _THREAD_SAFE */ +# define SYSCALL(x) __ALIAS(_thread_sys_,x) \ + __SYSCALL(_thread_sys_,x,x) +# define RSYSCALL(x) __ALIAS(_thread_sys_,x) \ + __PSEUDO(_thread_sys_,x,x) +# define PSEUDO(x,y) __ALIAS(_thread_sys_,x) \ + __PSEUDO(_thread_sys_,x,y) +# define PSEUDO_NOERROR(x,y) __ALIAS(_thread_sys_,x) \ + __PSEUDO_NOERROR(_thread_sys_,x,y) +# define SYSENTRY(x) __ALIAS(_thread_sys_,x) \ + __ENTRY(_thread_sys_,x) #define ASMSTR .asciz diff --git a/lib/libc/arch/vax/SYS.h b/lib/libc/arch/vax/SYS.h index 6f7a0966ce4..42a80fbea73 100644 --- a/lib/libc/arch/vax/SYS.h +++ b/lib/libc/arch/vax/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.11 2002/11/05 00:37:05 miod Exp $ */ +/* $OpenBSD: SYS.h,v 1.12 2002/11/05 22:19:55 marc Exp $ */ /* $NetBSD: SYS.h,v 1.4 1997/05/02 18:15:32 kleink Exp $ */ /* @@ -65,28 +65,28 @@ __DO_SYSCALL(y); \ ret -#ifdef _THREAD_SAFE +#ifdef __STDC__ +#define __ALIAS(prefix,name) \ + WEAK_ALIAS(name,prefix##name); +#else +#define __ALIAS(prefix,name) \ + WEAK_ALIAS(name,prefix/**/name); +#endif + /* * For the thread_safe versions, we prepend _thread_sys_ to the function * name so that the 'C' wrapper can go around the real name. */ -#define SYSCALL(x) __SYSCALL(_thread_sys_,x,x) -#define RSYSCALL(x) __PSEUDO(_thread_sys_,x,x) -#define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) -#define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) -#define SYSENTRY(x) __ENTRY(_thread_sys_,x) +#define SYSCALL(x) __ALIAS(_thread_sys_,x) \ + __SYSCALL(_thread_sys_,x,x) +#define RSYSCALL(x) __ALIAS(_thread_sys_,x) \ + __PSEUDO(_thread_sys_,x,x) +#define PSEUDO(x,y) __ALIAS(_thread_sys_,x) \ + __PSEUDO(_thread_sys_,x,y) +#define PSEUDO_NOERROR(x,y) __ALIAS(_thread_sys_,x) \ + __PSEUDO_NOERROR(_thread_sys_,x,y) +#define SYSENTRY(x) __ALIAS(_thread_sys_,x) \ + __ENTRY(_thread_sys_,x) #define SYSNAME(x) _CAT(__thread_sys_,x) -#else _THREAD_SAFE -/* - * The non-threaded library defaults to traditional syscalls where - * the function name matches the syscall name. - */ -#define SYSCALL(x) __SYSCALL(,x,x) -#define RSYSCALL(x) __PSEUDO(,x,x) -#define PSEUDO(x,y) __PSEUDO(,x,y) -#define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(,x,y) -#define SYSENTRY(x) __ENTRY(,x) -#define SYSNAME(x) _CAT(_,x) -#endif _THREAD_SAFE .globl __cerror diff --git a/lib/libc/include/thread_private.h b/lib/libc/include/thread_private.h index 89faade556c..0b0be6cb389 100644 --- a/lib/libc/include/thread_private.h +++ b/lib/libc/include/thread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: thread_private.h,v 1.13 2002/11/03 23:58:39 marc Exp $ */ +/* $OpenBSD: thread_private.h,v 1.14 2002/11/05 22:19:55 marc Exp $ */ #ifndef _THREAD_PRIVATE_H_ #define _THREAD_PRIVATE_H_ @@ -18,19 +18,7 @@ extern int __isthreaded; * Use WEAK_NAME(n) to get a libc-private name for n (_weak_n), * WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n, * WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n). - * - * If the symbol _NO_WEAK_ALIASES is defined, then symbols will be */ - -#ifdef _NO_WEAK_ALIASES -#ifdef _THREAD_SAFE -#define WEAK_NAME(name) __CONCAT(_weak,name) -#else -#define WEAK_NAME(name) name -#endif -#define WEAK_ALIAS(name) /* unavailable */ -#define WEAK_PROTOTYPE(name) /* unnecessary */ -#else /* !_NO_WEAK_ALIASES */ #define WEAK_NAME(name) __CONCAT(_weak_,name) #define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name)) #ifdef __GNUC__ @@ -38,7 +26,6 @@ extern int __isthreaded; #else #define WEAK_PROTOTYPE(name) /* typeof() only in gcc */ #endif -#endif /* !_NO_WEAK_ALIASES */ /* * These macros help in making persistent storage thread-specific. @@ -62,7 +49,7 @@ struct _thread_private_key_struct { void _libc_private_storage_lock(pthread_mutex_t *); void _libc_private_storage_unlock(pthread_mutex_t *); void * _libc_private_storage(volatile struct _thread_private_key_struct *, - void *, size_t, void *); + void *, size_t, void *); /* Declare a module mutex. */ #define _THREAD_PRIVATE_MUTEX(name) \ @@ -97,18 +84,7 @@ void * _libc_private_storage(volatile struct _thread_private_key_struct *, */ #define _THREAD_PRIVATE(keyname, storage, error) \ _libc_private_storage(&__THREAD_KEY_NAME(keyname), \ - &(storage), sizeof (storage), error) - -/* - * Macros for locking and unlocking FILEs. These test if the - * process is threaded to avoid locking when not required. - */ -#ifdef _FLOCK_DEBUG -#define FLOCKFILE(fp) _flockfile_debug(fp, __FILE__, __LINE__) -#else -#define FLOCKFILE(fp) flockfile(fp) -#endif -#define FUNLOCKFILE(fp) funlockfile(fp) + &(storage), sizeof (storage), error) /* * File descriptor locking definitions. @@ -117,19 +93,33 @@ void * _libc_private_storage(volatile struct _thread_private_key_struct *, #define FD_WRITE 0x2 #define FD_RDWR (FD_READ | FD_WRITE) -#ifdef _LOCK_DEBUG -#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock_debug(_fd, _type, \ - _ts, __FILE__, __LINE__) -#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock_debug(_fd, _type, \ - __FILE__, __LINE__) -#else -#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts) -#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type) -#endif +#define _FD_LOCK(_fd,_type,_ts) \ + _thread_fd_lock(_fd, _type, _ts, __FILE__, __LINE__) +#define _FD_UNLOCK(_fd,_type) \ + _thread_fd_unlock(_fd, _type, __FILE__, __LINE__) -int _thread_fd_lock(int, int, struct timespec *); -int _thread_fd_lock_debug(int, int, struct timespec *, char *, int); -void _thread_fd_unlock(int, int); -void _thread_fd_unlock_debug(int, int, char *, int); +int _thread_fd_lock(int, int, struct timespec *, const char *, int); +void _thread_fd_unlock(int, int, const char *, int); + +/* + * malloc lock/unlock definitions + */ +# define _MALLOC_LOCK() do { \ + if (__isthreaded) \ + _thread_malloc_lock(); \ + } while (0) +# define _MALLOC_UNLOCK() do { \ + if (__isthreaded) \ + _thread_malloc_unlock();\ + } while (0) +# define _MALLOC_LOCK_INIT()do { \ + if (__isthreaded) \ + _thread_malloc_init();\ + } while (0) + + +void _thread_malloc_init(void); +void _thread_malloc_lock(void); +void _thread_malloc_unlock(void); #endif /* _THREAD_PRIVATE_H_ */ diff --git a/lib/libc/stdlib/abort.c b/lib/libc/stdlib/abort.c index 7252cd8a8b2..a833a1a8b78 100644 --- a/lib/libc/stdlib/abort.c +++ b/lib/libc/stdlib/abort.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: abort.c,v 1.10 2002/11/03 23:58:39 marc Exp $"; +static char *rcsid = "$OpenBSD: abort.c,v 1.11 2002/11/05 22:19:55 marc Exp $"; #endif /* LIBC_SCCS and not lint */ #include <signal.h> @@ -55,11 +55,7 @@ abort() * any errors -- X311J doesn't allow abort to return anyway. */ sigdelset(&mask, SIGABRT); -#ifdef _THREAD_SAFE (void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#else /* _THREAD_SAFE */ - (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#endif /* _THREAD_SAFE */ /* * POSIX requires we flush stdio buffers on abort @@ -80,11 +76,7 @@ abort() * it again, only harder. */ (void)signal(SIGABRT, SIG_DFL); -#ifdef _THREAD_SAFE (void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#else /* _THREAD_SAFE */ - (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#endif /* _THREAD_SAFE */ (void)kill(getpid(), SIGABRT); exit(1); } diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 2ebc1eff05f..3cdacc59b9f 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.50 2002/11/03 23:58:39 marc Exp $"; +static char rcsid[] = "$OpenBSD: malloc.c,v 1.51 2002/11/05 22:19:55 marc Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -48,6 +48,8 @@ static char rcsid[] = "$OpenBSD: malloc.c,v 1.50 2002/11/03 23:58:39 marc Exp $" #include <fcntl.h> #include <errno.h> +#include "thread_private.h" + /* * The basic parameters you can tweak. * @@ -67,39 +69,6 @@ static char rcsid[] = "$OpenBSD: malloc.c,v 1.50 2002/11/03 23:58:39 marc Exp $" # define malloc_pageshift 13U #endif /* __OpenBSD__ */ -#ifdef _THREAD_SAFE -# 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() - /* - * Malloc can't use the wrapped write() if it fails very early, so - * we use the unwrapped syscall _thread_sys_write() - */ -# define write _thread_sys_write - ssize_t write(int, const void *, size_t); -# undef malloc -# undef realloc -# undef free -# endif -#else - /* no threads */ -# define THREAD_LOCK() -# define THREAD_UNLOCK() -# define THREAD_LOCK_INIT() -#endif - /* * No user serviceable parts behind this point. * @@ -494,7 +463,7 @@ malloc_init () int i, j; int save_errno = errno; - THREAD_LOCK_INIT(); + _MALLOC_LOCK_INIT(); INIT_MMAP(); @@ -1244,17 +1213,17 @@ malloc(size_t size) register void *r; malloc_func = " in malloc():"; - THREAD_LOCK(); + _MALLOC_LOCK(); if (malloc_active++) { wrtwarning("recursive call.\n"); malloc_active--; - THREAD_UNLOCK(); + _MALLOC_UNLOCK(); return (0); } r = imalloc(size); UTRACE(0, size, r); malloc_active--; - THREAD_UNLOCK(); + _MALLOC_UNLOCK(); if (malloc_xmalloc && !r) wrterror("out of memory.\n"); return (r); @@ -1264,17 +1233,17 @@ void free(void *ptr) { malloc_func = " in free():"; - THREAD_LOCK(); + _MALLOC_LOCK(); if (malloc_active++) { wrtwarning("recursive call.\n"); malloc_active--; - THREAD_UNLOCK(); + _MALLOC_UNLOCK(); return; } ifree(ptr); UTRACE(ptr, 0, 0); malloc_active--; - THREAD_UNLOCK(); + _MALLOC_UNLOCK(); return; } @@ -1284,11 +1253,11 @@ realloc(void *ptr, size_t size) register void *r; malloc_func = " in realloc():"; - THREAD_LOCK(); + _MALLOC_LOCK(); if (malloc_active++) { wrtwarning("recursive call.\n"); malloc_active--; - THREAD_UNLOCK(); + _MALLOC_UNLOCK(); return (0); } if (!ptr) { @@ -1298,7 +1267,7 @@ realloc(void *ptr, size_t size) } UTRACE(ptr, size, r); malloc_active--; - THREAD_UNLOCK(); + _MALLOC_UNLOCK(); if (malloc_xmalloc && !r) wrterror("out of memory.\n"); return (r); diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 10e43db90e7..fc9c4238d19 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,15 +1,10 @@ -# $OpenBSD: Makefile.inc,v 1.59 2002/11/03 23:58:39 marc Exp $ +# $OpenBSD: Makefile.inc,v 1.60 2002/11/05 22:19:55 marc Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 # sys sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/sys ${LIBCSRCDIR}/sys -# for now, only arch's below have weak aliases enabled -.if ${MACHINE_ARCH} != "i386" && ${ELF_TOOLCHAIN} != "yes" -CFLAGS+= -D_NO_WEAK_ALIASES -.endif - # modules with non-default implementations on at least one architecture: SRCS+= Ovfork.S brk.S cerror.S exect.S fork.S rfork.S \ sbrk.S sigpending.S sigprocmask.S sigreturn.S \ diff --git a/lib/libc/thread/Makefile.inc b/lib/libc/thread/Makefile.inc index b28dfd676ae..356bf1a3cc9 100644 --- a/lib/libc/thread/Makefile.inc +++ b/lib/libc/thread/Makefile.inc @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile.inc,v 1.4 2002/11/03 23:58:39 marc Exp $ +# $OpenBSD: Makefile.inc,v 1.5 2002/11/05 22:19:55 marc Exp $ .PATH: ${LIBCSRCDIR}/thread -SRCS+= thread_fd.c unithread_storage.c +SRCS+= thread_fd.c unithread_storage.c unithread_malloc_lock.c diff --git a/lib/libc/thread/thread_fd.c b/lib/libc/thread/thread_fd.c index c93d15825eb..f2a9ae2290b 100644 --- a/lib/libc/thread/thread_fd.c +++ b/lib/libc/thread/thread_fd.c @@ -1,52 +1,25 @@ -/* $OpenBSD: thread_fd.c,v 1.6 2002/11/03 23:58:39 marc Exp $ */ +/* $OpenBSD: thread_fd.c,v 1.7 2002/11/05 22:19:55 marc Exp $ */ #include <sys/time.h> #include <pthread.h> #include "thread_private.h" WEAK_PROTOTYPE(_thread_fd_lock); -WEAK_PROTOTYPE(_thread_fd_lock_debug); WEAK_PROTOTYPE(_thread_fd_unlock); -WEAK_PROTOTYPE(_thread_fd_unlock_debug); WEAK_ALIAS(_thread_fd_lock); -WEAK_ALIAS(_thread_fd_lock_debug); WEAK_ALIAS(_thread_fd_unlock); -WEAK_ALIAS(_thread_fd_unlock_debug); int -WEAK_NAME(_thread_fd_lock)(fd, lock_type, timeout) - int fd; - int lock_type; - struct timespec *timeout; +WEAK_NAME(_thread_fd_lock)(int fd, int lock_type, struct timespec *timeout, + const char *fname, int lineno) { return 0; } -int -WEAK_NAME(_thread_fd_lock_debug)(fd, lock_type, timeout, fname, lineno) - int fd; - int lock_type; - struct timespec *timeout; - char *fname; - int lineno; -{ - return 0; -} - -void -WEAK_NAME(_thread_fd_unlock)(fd, lock_type) - int fd; - int lock_type; -{ -} - void -WEAK_NAME(_thread_fd_unlock_debug)(fd, lock_type, fname, lineno) - int fd; - int lock_type; - char *fname; - int lineno; +WEAK_NAME(_thread_fd_unlock)(int fd, int lock_type, const char *fname, + int lineno) { } diff --git a/lib/libc/thread/unithread_malloc_lock.c b/lib/libc/thread/unithread_malloc_lock.c index 1b33b29a495..74855be7821 100644 --- a/lib/libc/thread/unithread_malloc_lock.c +++ b/lib/libc/thread/unithread_malloc_lock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unithread_malloc_lock.c,v 1.3 2002/11/03 23:58:39 marc Exp $ */ +/* $OpenBSD: unithread_malloc_lock.c,v 1.4 2002/11/05 22:19:55 marc Exp $ */ #include <sys/cdefs.h> #include <pthread.h> @@ -6,16 +6,26 @@ WEAK_PROTOTYPE(_thread_malloc_lock); WEAK_PROTOTYPE(_thread_malloc_unlock); +WEAK_PROTOTYPE(_thread_malloc_init); WEAK_ALIAS(_thread_malloc_lock); WEAK_ALIAS(_thread_malloc_unlock); +WEAK_ALIAS(_thread_malloc_init); void -WEAK_NAME(_thread_malloc_lock)() +WEAK_NAME(_thread_malloc_lock)(void) { + return; } void -WEAK_NAME(_thread_malloc_unlock)() +WEAK_NAME(_thread_malloc_unlock)(void) { + return; +} + +void +WEAK_NAME(_thread_malloc_init)(void) +{ + return; } diff --git a/lib/libc_r/thread/Makefile.inc b/lib/libc_r/thread/Makefile.inc index f98a910165c..7d9e4a17fa7 100644 --- a/lib/libc_r/thread/Makefile.inc +++ b/lib/libc_r/thread/Makefile.inc @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile.inc,v 1.3 2002/11/03 23:58:39 marc Exp $ +# $OpenBSD: Makefile.inc,v 1.4 2002/11/05 22:19:55 marc Exp $ .PATH: ${LIBC_RSRCDIR}/thread -SRCS+= thread_storage.c +SRCS+= thread_storage.c thread_malloc_lock.c diff --git a/lib/libc_r/thread/thread_malloc_lock.c b/lib/libc_r/thread/thread_malloc_lock.c index 68f899983cb..8755b1dad27 100644 --- a/lib/libc_r/thread/thread_malloc_lock.c +++ b/lib/libc_r/thread/thread_malloc_lock.c @@ -1,7 +1,8 @@ +/* $OpenBSD: thread_malloc_lock.c,v 1.4 2002/11/05 22:19:55 marc Exp $ */ +/* Public Domain <marc@snafu.org> */ + #include <pthread.h> #include "pthread_private.h" -#include "thread_private.h" -#include "spinlock.h" static spinlock_t malloc_lock = _SPINLOCK_INITIALIZER; @@ -16,3 +17,8 @@ _thread_malloc_unlock() { _SPINUNLOCK(&malloc_lock); } + +void +_thread_malloc_init() +{ +} diff --git a/lib/libc_r/thread/thread_storage.c b/lib/libc_r/thread/thread_storage.c index fa8357c85ec..61609f9c277 100644 --- a/lib/libc_r/thread/thread_storage.c +++ b/lib/libc_r/thread/thread_storage.c @@ -1,5 +1,9 @@ +/* $OpenBSD: thread_storage.c,v 1.6 2002/11/05 22:19:55 marc Exp $ */ +/* Public Domain */ -/* libpthread's stronger functions */ +/* + * libpthread's stronger functions + */ #include <stdlib.h> #include <pthread.h> diff --git a/lib/libc_r/uthread/uthread_fd.c b/lib/libc_r/uthread/uthread_fd.c index 4875cd10fb1..19bc48f2cc9 100644 --- a/lib/libc_r/uthread/uthread_fd.c +++ b/lib/libc_r/uthread/uthread_fd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_fd.c,v 1.13 2002/11/03 23:58:39 marc Exp $ */ +/* $OpenBSD: uthread_fd.c,v 1.14 2002/11/05 22:19:56 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -145,7 +145,7 @@ _thread_fd_table_init(int fd) */ void _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type, - char *fname, int lineno) + const char *fname, int lineno) { struct fd_table_entry *entry; int ret; @@ -170,7 +170,7 @@ _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type, * thread's accesses: */ if (fname) - _spinlock_debug(&entry->lock, fname, lineno); + _spinlock_debug(&entry->lock, (char *)fname, lineno); else _SPINLOCK(&entry->lock); @@ -266,7 +266,7 @@ _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type, * fname and lineno (debug variables). */ void -_thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) +_thread_fd_unlock(int fd, int lock_type, const char *fname, int lineno) { struct pthread *curthread = _get_curthread(); return (_thread_fd_unlock_thread(curthread, fd, lock_type, @@ -274,17 +274,6 @@ _thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) } /* - * Unlock an fd table entry for the given fd and lock type (read, - * write, or read-write). - */ -void -_thread_fd_unlock(int fd, int lock_type) -{ - struct pthread *curthread = _get_curthread(); - return (_thread_fd_unlock_thread(curthread, fd, lock_type, NULL, 0)); -} - -/* * Unlock all fd table entries owned by the given thread */ void @@ -323,8 +312,8 @@ _thread_fd_unlock_owned(pthread_t pthread) * null when called by the non-debug version of the function. */ int -_thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, - char *fname, int lineno) +_thread_fd_lock(int fd, int lock_type, struct timespec * timeout, + const char *fname, int lineno) { struct pthread *curthread = _get_curthread(); struct fd_table_entry *entry; @@ -344,7 +333,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * thread's accesses: */ if (fname) - _spinlock_debug(&entry->lock, fname, lineno); + _spinlock_debug(&entry->lock, (char *)fname, lineno); else _SPINLOCK(&entry->lock); @@ -376,7 +365,8 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, */ curthread->data.fd.fd = fd; curthread->data.fd.branch = lineno; - curthread->data.fd.fname = fname; + curthread->data.fd.fname = + (char *)fname; /* Set the timeout: */ _thread_kern_set_timeout(timeout); @@ -455,7 +445,8 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, */ curthread->data.fd.fd = fd; curthread->data.fd.branch = lineno; - curthread->data.fd.fname = fname; + curthread->data.fd.fname = + (char *)fname; /* Set the timeout: */ _thread_kern_set_timeout(timeout); @@ -512,14 +503,4 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, return (ret); } -/* - * Non-debug version of fd locking. Just call the debug version - * passing a null file and line - */ -int -_thread_fd_lock(int fd, int lock_type, struct timespec * timeout) -{ - return (_thread_fd_lock_debug(fd, lock_type, timeout, NULL, 0)); -} - #endif diff --git a/lib/libpthread/thread/Makefile.inc b/lib/libpthread/thread/Makefile.inc index f98a910165c..7d9e4a17fa7 100644 --- a/lib/libpthread/thread/Makefile.inc +++ b/lib/libpthread/thread/Makefile.inc @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile.inc,v 1.3 2002/11/03 23:58:39 marc Exp $ +# $OpenBSD: Makefile.inc,v 1.4 2002/11/05 22:19:55 marc Exp $ .PATH: ${LIBC_RSRCDIR}/thread -SRCS+= thread_storage.c +SRCS+= thread_storage.c thread_malloc_lock.c diff --git a/lib/libpthread/thread/thread_malloc_lock.c b/lib/libpthread/thread/thread_malloc_lock.c index 68f899983cb..8755b1dad27 100644 --- a/lib/libpthread/thread/thread_malloc_lock.c +++ b/lib/libpthread/thread/thread_malloc_lock.c @@ -1,7 +1,8 @@ +/* $OpenBSD: thread_malloc_lock.c,v 1.4 2002/11/05 22:19:55 marc Exp $ */ +/* Public Domain <marc@snafu.org> */ + #include <pthread.h> #include "pthread_private.h" -#include "thread_private.h" -#include "spinlock.h" static spinlock_t malloc_lock = _SPINLOCK_INITIALIZER; @@ -16,3 +17,8 @@ _thread_malloc_unlock() { _SPINUNLOCK(&malloc_lock); } + +void +_thread_malloc_init() +{ +} diff --git a/lib/libpthread/thread/thread_storage.c b/lib/libpthread/thread/thread_storage.c index fa8357c85ec..61609f9c277 100644 --- a/lib/libpthread/thread/thread_storage.c +++ b/lib/libpthread/thread/thread_storage.c @@ -1,5 +1,9 @@ +/* $OpenBSD: thread_storage.c,v 1.6 2002/11/05 22:19:55 marc Exp $ */ +/* Public Domain */ -/* libpthread's stronger functions */ +/* + * libpthread's stronger functions + */ #include <stdlib.h> #include <pthread.h> diff --git a/lib/libpthread/uthread/uthread_fd.c b/lib/libpthread/uthread/uthread_fd.c index 4875cd10fb1..19bc48f2cc9 100644 --- a/lib/libpthread/uthread/uthread_fd.c +++ b/lib/libpthread/uthread/uthread_fd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_fd.c,v 1.13 2002/11/03 23:58:39 marc Exp $ */ +/* $OpenBSD: uthread_fd.c,v 1.14 2002/11/05 22:19:56 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -145,7 +145,7 @@ _thread_fd_table_init(int fd) */ void _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type, - char *fname, int lineno) + const char *fname, int lineno) { struct fd_table_entry *entry; int ret; @@ -170,7 +170,7 @@ _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type, * thread's accesses: */ if (fname) - _spinlock_debug(&entry->lock, fname, lineno); + _spinlock_debug(&entry->lock, (char *)fname, lineno); else _SPINLOCK(&entry->lock); @@ -266,7 +266,7 @@ _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type, * fname and lineno (debug variables). */ void -_thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) +_thread_fd_unlock(int fd, int lock_type, const char *fname, int lineno) { struct pthread *curthread = _get_curthread(); return (_thread_fd_unlock_thread(curthread, fd, lock_type, @@ -274,17 +274,6 @@ _thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) } /* - * Unlock an fd table entry for the given fd and lock type (read, - * write, or read-write). - */ -void -_thread_fd_unlock(int fd, int lock_type) -{ - struct pthread *curthread = _get_curthread(); - return (_thread_fd_unlock_thread(curthread, fd, lock_type, NULL, 0)); -} - -/* * Unlock all fd table entries owned by the given thread */ void @@ -323,8 +312,8 @@ _thread_fd_unlock_owned(pthread_t pthread) * null when called by the non-debug version of the function. */ int -_thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, - char *fname, int lineno) +_thread_fd_lock(int fd, int lock_type, struct timespec * timeout, + const char *fname, int lineno) { struct pthread *curthread = _get_curthread(); struct fd_table_entry *entry; @@ -344,7 +333,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * thread's accesses: */ if (fname) - _spinlock_debug(&entry->lock, fname, lineno); + _spinlock_debug(&entry->lock, (char *)fname, lineno); else _SPINLOCK(&entry->lock); @@ -376,7 +365,8 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, */ curthread->data.fd.fd = fd; curthread->data.fd.branch = lineno; - curthread->data.fd.fname = fname; + curthread->data.fd.fname = + (char *)fname; /* Set the timeout: */ _thread_kern_set_timeout(timeout); @@ -455,7 +445,8 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, */ curthread->data.fd.fd = fd; curthread->data.fd.branch = lineno; - curthread->data.fd.fname = fname; + curthread->data.fd.fname = + (char *)fname; /* Set the timeout: */ _thread_kern_set_timeout(timeout); @@ -512,14 +503,4 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, return (ret); } -/* - * Non-debug version of fd locking. Just call the debug version - * passing a null file and line - */ -int -_thread_fd_lock(int fd, int lock_type, struct timespec * timeout) -{ - return (_thread_fd_lock_debug(fd, lock_type, timeout, NULL, 0)); -} - #endif |