diff options
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/getgrent.c | 3 | ||||
-rw-r--r-- | lib/libc/include/thread_private.h | 160 | ||||
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 4 | ||||
-rw-r--r-- | lib/libc/net/getnameinfo.c | 4 | ||||
-rw-r--r-- | lib/libc/net/res_init.c | 12 | ||||
-rw-r--r-- | lib/libc/shlib_version | 2 | ||||
-rw-r--r-- | lib/libc/stdio/flockfile.c | 15 | ||||
-rw-r--r-- | lib/libc/sys/ftruncate.c | 4 | ||||
-rw-r--r-- | lib/libc/sys/lseek.c | 4 | ||||
-rw-r--r-- | lib/libc/thread/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/thread/thread_fd.c | 9 | ||||
-rw-r--r-- | lib/libc/thread/unithread_malloc_lock.c | 5 | ||||
-rw-r--r-- | lib/libc/thread/unithread_storage.c | 40 | ||||
-rw-r--r-- | lib/libc/thread/unithread_tag.c | 32 |
14 files changed, 133 insertions, 165 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 1d157d679e2..558aea40ff4 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -29,7 +29,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getgrent.c,v 1.20 2004/05/18 02:05:52 jfb Exp $"; +static char rcsid[] = "$OpenBSD: getgrent.c,v 1.21 2004/06/07 21:11:23 marc Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -59,7 +59,6 @@ static struct group_storage { /* File pointers are locked with the 'gr' mutex */ _THREAD_PRIVATE_KEY(gr); -_THREAD_PRIVATE_MUTEX(gr); static FILE *_gr_fp; static struct group _gr_group; static int _gr_stayopen; diff --git a/lib/libc/include/thread_private.h b/lib/libc/include/thread_private.h index 4212e7dcb2e..edac6b008d0 100644 --- a/lib/libc/include/thread_private.h +++ b/lib/libc/include/thread_private.h @@ -1,13 +1,19 @@ -/* $OpenBSD: thread_private.h,v 1.15 2003/01/28 04:58:00 marc Exp $ */ +/* $OpenBSD: thread_private.h,v 1.16 2004/06/07 21:11:23 marc Exp $ */ + +/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ #ifndef _THREAD_PRIVATE_H_ #define _THREAD_PRIVATE_H_ -#include <pthread.h> +/* + * This file defines the thread library interface to libc. Thread + * libraries must implement the functions described here for proper + * inter-operation with libc. libc contains weak versions of the + * described functions for operation in a non-threaded environment. + */ /* - * This variable is initially 0 when there is exactly one thread. - * It should never decrease. + * This variable is 0 until a second thread is created. */ extern int __isthreaded; @@ -19,116 +25,102 @@ extern int __isthreaded; * 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). */ -#define WEAK_NAME(name) __CONCAT(_weak_,name) -#define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name)) +#define WEAK_NAME(name) __CONCAT(_weak_,name) +#define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name)) #ifdef __GNUC__ -#define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name) +#define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name) #else -#define WEAK_PROTOTYPE(name) /* typeof() only in gcc */ +#define WEAK_PROTOTYPE(name) /* typeof() only in gcc */ #endif /* - * These macros help in making persistent storage thread-specific. - * Libc makes extensive use of private static data structures - * that hold state across function invocation, and these macros - * are no-ops when running single-threaded. - * - * Linking against the user-thread library causes these macros to - * allocate storage on a per-thread basis. + * helper macro to make unique names in the thread namespace */ - -#define __THREAD_MUTEX_NAME(name) __CONCAT(_libc_storage_mutex_,name) -#define __THREAD_KEY_NAME(name) __CONCAT(_libc_storage_key_,name) - -struct _thread_private_key_struct { - pthread_once_t once; - void (*cleanfn)(void *); - pthread_key_t key; -}; - -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 *); - -/* Declare a module mutex. */ -#define _THREAD_PRIVATE_MUTEX(name) \ - static pthread_mutex_t __THREAD_MUTEX_NAME(name) = \ - PTHREAD_MUTEX_INITIALIZER - -/* Lock a module mutex against use by any other threads. */ -#define _THREAD_PRIVATE_MUTEX_LOCK(name) \ - _libc_private_storage_lock(&__THREAD_MUTEX_NAME(name)) - -/* Unlock a module mutex. */ -#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \ - _libc_private_storage_unlock(&__THREAD_MUTEX_NAME(name)) - -/* Declare a thread-private storage key. */ -#define _THREAD_PRIVATE_KEY(name) \ - static volatile struct _thread_private_key_struct \ - __THREAD_KEY_NAME(name) = { \ - PTHREAD_ONCE_INIT, \ - 0 \ - } +#define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name) /* - * In threaded mode, return a pointer to thread-private memory of - * the same size as, and (initially) with the same contents as 'storage'. If - * an error occurs, the 'error' parameter is returned. - * In single-threaded mode, no storage is allocated. Instead, a pointer - * to storage is always returned. - * The 'cleanfn' function of the key structure is called to free the storage. - * If 'cleanfn' is NULL, then free() is used. This hook can be useful for - * getting rid of memory leaks. + * helper functions that exist as (weak) null functions in libc and + * (strong) functions in the thread library. These functions: + * + * _thread_tag_lock: + * lock the mutex associated with the given tag. If the given + * tag is NULL a tag is first allocated. + * + * _thread_tag_unlock: + * unlock the mutex associated with the given tag. If the given + * tag is NULL a tag is first allocated. + * + * _thread_tag_storage: + * return a pointer to per thread instance of data associated + * with the given tag. If the given tag is NULL a tag is first + * allocated. */ -#define _THREAD_PRIVATE(keyname, storage, error) \ - _libc_private_storage(&__THREAD_KEY_NAME(keyname), \ - &(storage), sizeof (storage), error) +void _thread_tag_lock(void **); +void _thread_tag_unlock(void **); +void *_thread_tag_storage(void **, void *, size_t, void *); /* - * Keys used to access the per thread instances of resolver global data. - * These are not static as they are referenced in several places. + * Macros used in libc to access thread mutex, keys, and per thread storage. + * _THREAD_PRIVATE_KEY and _THREAD_PRIVATE_MUTEX are different macros for + * historical reasons. They do the same thing, define a static variable + * keyed by 'name' that identifies a mutex and a key to identify per thread + * data. */ -extern volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res); -#ifdef INET6 -extern volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res_ext); -#endif +#define _THREAD_PRIVATE_KEY(name) \ + static void *__THREAD_NAME(name) +#define _THREAD_PRIVATE_MUTEX(name) \ + static void *__THREAD_NAME(name) +#define _THREAD_PRIVATE_MUTEX_LOCK(name) \ + _thread_tag_lock(&(__THREAD_NAME(name))) +#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \ + _thread_tag_unlock(&(__THREAD_NAME(name))) +#define _THREAD_PRIVATE(keyname, storage, error) \ + _thread_tag_storage(&(__THREAD_NAME(keyname)), &(storage), \ + sizeof (storage), error) +/* + * Resolver code is special cased in that it uses global keys. + */ +extern void *__THREAD_NAME(_res); +extern void *__THREAD_NAME(_res_ext); +extern void *__THREAD_NAME(serv_mutex); /* * File descriptor locking definitions. */ -#define FD_READ 0x1 -#define FD_WRITE 0x2 -#define FD_RDWR (FD_READ | FD_WRITE) +#define FD_READ 0x1 +#define FD_WRITE 0x2 +#define FD_RDWR (FD_READ | FD_WRITE) + +int _thread_fd_lock(int, int, struct timespec *); +void _thread_fd_unlock(int, int); -#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__) +/* + * Macros are used in libc code for historical (debug) reasons. + * Define them here. + */ +#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts) +#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type) -int _thread_fd_lock(int, int, struct timespec *, const char *, int); -void _thread_fd_unlock(int, int, const char *, int); /* - * malloc lock/unlock definitions + * malloc lock/unlock prototypes and definitions */ -# define _MALLOC_LOCK() do { \ +void _thread_malloc_init(void); +void _thread_malloc_lock(void); +void _thread_malloc_unlock(void); + +#define _MALLOC_LOCK() do { \ if (__isthreaded) \ _thread_malloc_lock(); \ } while (0) -# define _MALLOC_UNLOCK() do { \ +#define _MALLOC_UNLOCK() do { \ if (__isthreaded) \ _thread_malloc_unlock();\ } while (0) -# define _MALLOC_LOCK_INIT()do { \ +#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/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index 8fb8975ad83..3db8cc82ee9 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo.c,v 1.49 2004/04/14 07:06:15 itojun Exp $ */ +/* $OpenBSD: getaddrinfo.c,v 1.50 2004/06/07 21:11:23 marc Exp $ */ /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ /* @@ -873,7 +873,7 @@ get_port(ai, servname, matchonly) int port; int allownumeric; /* mutex is defined in getnameinfo.c */ - extern pthread_mutex_t __THREAD_MUTEX_NAME(serv_mutex); + extern void *__THREAD_NAME(serv_mutex); if (servname == NULL) return 0; diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index da5df507ab0..62760e178da 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnameinfo.c,v 1.27 2003/07/21 23:17:53 marc Exp $ */ +/* $OpenBSD: getnameinfo.c,v 1.28 2004/06/07 21:11:23 marc Exp $ */ /* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ /* @@ -91,7 +91,7 @@ static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int); /* * this mutex is also used by get_port in getaddrinfo.c */ -pthread_mutex_t __THREAD_MUTEX_NAME(serv_mutex) = PTHREAD_MUTEX_INITIALIZER; +void *__THREAD_NAME(serv_mutex); int getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c index 9c739588836..79ccada6eeb 100644 --- a/lib/libc/net/res_init.c +++ b/lib/libc/net/res_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_init.c,v 1.29 2003/06/02 20:18:36 millert Exp $ */ +/* $OpenBSD: res_init.c,v 1.30 2004/06/07 21:11:23 marc Exp $ */ /* * ++Copyright++ 1985, 1989, 1993 @@ -60,7 +60,7 @@ static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_init.c,v 1.29 2003/06/02 20:18:36 millert Exp $"; +static char rcsid[] = "$OpenBSD: res_init.c,v 1.30 2004/06/07 21:11:23 marc Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -118,9 +118,7 @@ static u_int32_t net_mask(struct in_addr); /* * Resolver state default settings. */ -volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res) = { - PTHREAD_ONCE_INIT, 0 -}; +void *__THREAD_NAME(_res); struct __res_state _res # if defined(__BIND_RES_TEXT) @@ -128,9 +126,7 @@ struct __res_state _res # endif ; #ifdef INET6 -volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res_ext) = { - PTHREAD_ONCE_INIT, 0 -}; +void *__THREAD_NAME(_res_ext); struct __res_state_ext _res_ext; #endif /* INET6 */ diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index 59270a5cade..785601b1fd8 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,2 +1,2 @@ -major=31 +major=32 minor=0 # note: remember to update minor in ../libpthread/shlib_version diff --git a/lib/libc/stdio/flockfile.c b/lib/libc/stdio/flockfile.c index e0963391596..35cadb38284 100644 --- a/lib/libc/stdio/flockfile.c +++ b/lib/libc/stdio/flockfile.c @@ -1,5 +1,6 @@ -/* $OpenBSD: flockfile.c,v 1.5 2001/09/04 22:17:45 fgsch Exp $ */ +/* $OpenBSD: flockfile.c,v 1.6 2004/06/07 21:11:23 marc Exp $ */ +#include <sys/time.h> #include <stdio.h> #include "thread_private.h" @@ -12,17 +13,14 @@ #undef flockfile #undef ftrylockfile #undef funlockfile -#undef _flockfile_debug WEAK_PROTOTYPE(flockfile); WEAK_PROTOTYPE(ftrylockfile); WEAK_PROTOTYPE(funlockfile); -WEAK_PROTOTYPE(_flockfile_debug); WEAK_ALIAS(flockfile); WEAK_ALIAS(ftrylockfile); WEAK_ALIAS(funlockfile); -WEAK_ALIAS(_flockfile_debug); void WEAK_NAME(flockfile)(fp) @@ -44,12 +42,3 @@ WEAK_NAME(funlockfile)(fp) FILE * fp; { } - -void -WEAK_NAME(_flockfile_debug)(fp, fname, lineno) - FILE * fp; - char * fname; - int lineno; -{ -} - diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c index 8d95281064e..47670e5248d 100644 --- a/lib/libc/sys/ftruncate.c +++ b/lib/libc/sys/ftruncate.c @@ -28,11 +28,13 @@ */ #if defined(SYSLIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: ftruncate.c,v 1.11 2003/06/11 21:03:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ftruncate.c,v 1.12 2004/06/07 21:11:23 marc Exp $"; #endif /* SYSLIBC_SCCS and not lint */ #include <sys/types.h> #include <sys/syscall.h> +#include <sys/time.h> +#include <unistd.h> #include "thread_private.h" #ifdef lint diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c index d811ce9b8ae..b5c629e1b89 100644 --- a/lib/libc/sys/lseek.c +++ b/lib/libc/sys/lseek.c @@ -28,11 +28,13 @@ */ #if defined(SYSLIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: lseek.c,v 1.10 2003/06/11 21:03:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: lseek.c,v 1.11 2004/06/07 21:11:23 marc Exp $"; #endif /* SYSLIBC_SCCS and not lint */ #include <sys/types.h> +#include <sys/time.h> #include <sys/syscall.h> +#include <unistd.h> #include "thread_private.h" /* diff --git a/lib/libc/thread/Makefile.inc b/lib/libc/thread/Makefile.inc index 356bf1a3cc9..9d323879900 100644 --- a/lib/libc/thread/Makefile.inc +++ b/lib/libc/thread/Makefile.inc @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile.inc,v 1.5 2002/11/05 22:19:55 marc Exp $ +# $OpenBSD: Makefile.inc,v 1.6 2004/06/07 21:11:23 marc Exp $ .PATH: ${LIBCSRCDIR}/thread -SRCS+= thread_fd.c unithread_storage.c unithread_malloc_lock.c +SRCS+= thread_fd.c unithread_malloc_lock.c unithread_tag.c diff --git a/lib/libc/thread/thread_fd.c b/lib/libc/thread/thread_fd.c index f2a9ae2290b..9f10fedf837 100644 --- a/lib/libc/thread/thread_fd.c +++ b/lib/libc/thread/thread_fd.c @@ -1,7 +1,6 @@ -/* $OpenBSD: thread_fd.c,v 1.7 2002/11/05 22:19:55 marc Exp $ */ +/* $OpenBSD: thread_fd.c,v 1.8 2004/06/07 21:11:23 marc Exp $ */ #include <sys/time.h> -#include <pthread.h> #include "thread_private.h" WEAK_PROTOTYPE(_thread_fd_lock); @@ -11,15 +10,13 @@ WEAK_ALIAS(_thread_fd_lock); WEAK_ALIAS(_thread_fd_unlock); int -WEAK_NAME(_thread_fd_lock)(int fd, int lock_type, struct timespec *timeout, - const char *fname, int lineno) +WEAK_NAME(_thread_fd_lock)(int fd, int lock_type, struct timespec *timeout) { return 0; } void -WEAK_NAME(_thread_fd_unlock)(int fd, int lock_type, const char *fname, - int lineno) +WEAK_NAME(_thread_fd_unlock)(int fd, int lock_type) { } diff --git a/lib/libc/thread/unithread_malloc_lock.c b/lib/libc/thread/unithread_malloc_lock.c index 74855be7821..2c195a9a95c 100644 --- a/lib/libc/thread/unithread_malloc_lock.c +++ b/lib/libc/thread/unithread_malloc_lock.c @@ -1,7 +1,6 @@ -/* $OpenBSD: unithread_malloc_lock.c,v 1.4 2002/11/05 22:19:55 marc Exp $ */ +/* $OpenBSD: unithread_malloc_lock.c,v 1.5 2004/06/07 21:11:23 marc Exp $ */ -#include <sys/cdefs.h> -#include <pthread.h> +#include <sys/time.h> #include "thread_private.h" WEAK_PROTOTYPE(_thread_malloc_lock); diff --git a/lib/libc/thread/unithread_storage.c b/lib/libc/thread/unithread_storage.c deleted file mode 100644 index 456082a8a2b..00000000000 --- a/lib/libc/thread/unithread_storage.c +++ /dev/null @@ -1,40 +0,0 @@ -/* $OpenBSD: unithread_storage.c,v 1.1 2000/01/06 15:07:06 d Exp $ */ -/* - * - */ -/* unthreaded storage allocation helper functions */ - -#include <sys/cdefs.h> -#include <pthread.h> -#include "thread_private.h" - -WEAK_PROTOTYPE(_libc_private_storage_lock); -WEAK_PROTOTYPE(_libc_private_storage_unlock); -WEAK_PROTOTYPE(_libc_private_storage); - -WEAK_ALIAS(_libc_private_storage_lock); -WEAK_ALIAS(_libc_private_storage_unlock); -WEAK_ALIAS(_libc_private_storage); - -void -WEAK_NAME(_libc_private_storage_lock)(mutex) - pthread_mutex_t *mutex; -{ -} - -void -WEAK_NAME(_libc_private_storage_unlock)(mutex) - pthread_mutex_t *mutex; -{ -} - -void * -WEAK_NAME(_libc_private_storage)(key, init, initsz, error) - volatile struct _thread_private_key_struct * key; - void *init; - size_t initsz; - void *error; -{ - - return init; -} diff --git a/lib/libc/thread/unithread_tag.c b/lib/libc/thread/unithread_tag.c new file mode 100644 index 00000000000..c7ac928b994 --- /dev/null +++ b/lib/libc/thread/unithread_tag.c @@ -0,0 +1,32 @@ +/* $OpenBSD: unithread_tag.c,v 1.1 2004/06/07 21:11:23 marc Exp $ */ + +/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ + +#include <sys/time.h> +#include "thread_private.h" + +WEAK_PROTOTYPE(_thread_tag_lock); +WEAK_PROTOTYPE(_thread_tag_unlock); +WEAK_PROTOTYPE(_thread_tag_storage); + +WEAK_ALIAS(_thread_tag_lock); +WEAK_ALIAS(_thread_tag_unlock); +WEAK_ALIAS(_thread_tag_storage); + +void +WEAK_NAME(_thread_tag_lock)(void **tag) +{ + return; +} + +void +WEAK_NAME(_thread_tag_unlock)(void **tag) +{ + return; +} + +void * +WEAK_NAME(_thread_tag_storage)(void **tag, void *init, size_t initsz, void *err) +{ + return init; +} |