diff options
author | marc <> | 2004-06-07 21:11:23 +0000 |
---|---|---|
committer | marc <> | 2004-06-07 21:11:23 +0000 |
commit | ae9f75ae846c14c230b202c01a33e14601eb8c43 (patch) | |
tree | ca69c52ec58ad766023dae6e9617fc1e5fef2637 /src/lib | |
parent | bea8674d8fa57fb3227fdc5b14c3af3a00d97a20 (diff) | |
download | openbsd-ae9f75ae846c14c230b202c01a33e14601eb8c43.tar.gz openbsd-ae9f75ae846c14c230b202c01a33e14601eb8c43.tar.bz2 openbsd-ae9f75ae846c14c230b202c01a33e14601eb8c43.zip |
major bump to libc and libpthread to break the dependency of a
particular implementation of libpthread for libc. libc no longer
needs pthread.h to compile.
OK millert@, brad@, tedu@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/include/thread_private.h | 160 | ||||
-rw-r--r-- | src/lib/libc/net/getaddrinfo.c | 4 | ||||
-rw-r--r-- | src/lib/libc/net/getnameinfo.c | 4 | ||||
-rw-r--r-- | src/lib/libc/net/res_init.c | 12 |
4 files changed, 84 insertions, 96 deletions
diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h index 4212e7dcb2..edac6b008d 100644 --- a/src/lib/libc/include/thread_private.h +++ b/src/lib/libc/include/thread_private.h | |||
@@ -1,13 +1,19 @@ | |||
1 | /* $OpenBSD: thread_private.h,v 1.15 2003/01/28 04:58:00 marc Exp $ */ | 1 | /* $OpenBSD: thread_private.h,v 1.16 2004/06/07 21:11:23 marc Exp $ */ |
2 | |||
3 | /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ | ||
2 | 4 | ||
3 | #ifndef _THREAD_PRIVATE_H_ | 5 | #ifndef _THREAD_PRIVATE_H_ |
4 | #define _THREAD_PRIVATE_H_ | 6 | #define _THREAD_PRIVATE_H_ |
5 | 7 | ||
6 | #include <pthread.h> | 8 | /* |
9 | * This file defines the thread library interface to libc. Thread | ||
10 | * libraries must implement the functions described here for proper | ||
11 | * inter-operation with libc. libc contains weak versions of the | ||
12 | * described functions for operation in a non-threaded environment. | ||
13 | */ | ||
7 | 14 | ||
8 | /* | 15 | /* |
9 | * This variable is initially 0 when there is exactly one thread. | 16 | * This variable is 0 until a second thread is created. |
10 | * It should never decrease. | ||
11 | */ | 17 | */ |
12 | extern int __isthreaded; | 18 | extern int __isthreaded; |
13 | 19 | ||
@@ -19,116 +25,102 @@ extern int __isthreaded; | |||
19 | * WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n, | 25 | * WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n, |
20 | * WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n). | 26 | * WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n). |
21 | */ | 27 | */ |
22 | #define WEAK_NAME(name) __CONCAT(_weak_,name) | 28 | #define WEAK_NAME(name) __CONCAT(_weak_,name) |
23 | #define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name)) | 29 | #define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name)) |
24 | #ifdef __GNUC__ | 30 | #ifdef __GNUC__ |
25 | #define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name) | 31 | #define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name) |
26 | #else | 32 | #else |
27 | #define WEAK_PROTOTYPE(name) /* typeof() only in gcc */ | 33 | #define WEAK_PROTOTYPE(name) /* typeof() only in gcc */ |
28 | #endif | 34 | #endif |
29 | 35 | ||
30 | /* | 36 | /* |
31 | * These macros help in making persistent storage thread-specific. | 37 | * helper macro to make unique names in the thread namespace |
32 | * Libc makes extensive use of private static data structures | ||
33 | * that hold state across function invocation, and these macros | ||
34 | * are no-ops when running single-threaded. | ||
35 | * | ||
36 | * Linking against the user-thread library causes these macros to | ||
37 | * allocate storage on a per-thread basis. | ||
38 | */ | 38 | */ |
39 | 39 | #define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name) | |
40 | #define __THREAD_MUTEX_NAME(name) __CONCAT(_libc_storage_mutex_,name) | ||
41 | #define __THREAD_KEY_NAME(name) __CONCAT(_libc_storage_key_,name) | ||
42 | |||
43 | struct _thread_private_key_struct { | ||
44 | pthread_once_t once; | ||
45 | void (*cleanfn)(void *); | ||
46 | pthread_key_t key; | ||
47 | }; | ||
48 | |||
49 | void _libc_private_storage_lock(pthread_mutex_t *); | ||
50 | void _libc_private_storage_unlock(pthread_mutex_t *); | ||
51 | void * _libc_private_storage(volatile struct _thread_private_key_struct *, | ||
52 | void *, size_t, void *); | ||
53 | |||
54 | /* Declare a module mutex. */ | ||
55 | #define _THREAD_PRIVATE_MUTEX(name) \ | ||
56 | static pthread_mutex_t __THREAD_MUTEX_NAME(name) = \ | ||
57 | PTHREAD_MUTEX_INITIALIZER | ||
58 | |||
59 | /* Lock a module mutex against use by any other threads. */ | ||
60 | #define _THREAD_PRIVATE_MUTEX_LOCK(name) \ | ||
61 | _libc_private_storage_lock(&__THREAD_MUTEX_NAME(name)) | ||
62 | |||
63 | /* Unlock a module mutex. */ | ||
64 | #define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \ | ||
65 | _libc_private_storage_unlock(&__THREAD_MUTEX_NAME(name)) | ||
66 | |||
67 | /* Declare a thread-private storage key. */ | ||
68 | #define _THREAD_PRIVATE_KEY(name) \ | ||
69 | static volatile struct _thread_private_key_struct \ | ||
70 | __THREAD_KEY_NAME(name) = { \ | ||
71 | PTHREAD_ONCE_INIT, \ | ||
72 | 0 \ | ||
73 | } | ||
74 | 40 | ||
75 | /* | 41 | /* |
76 | * In threaded mode, return a pointer to thread-private memory of | 42 | * helper functions that exist as (weak) null functions in libc and |
77 | * the same size as, and (initially) with the same contents as 'storage'. If | 43 | * (strong) functions in the thread library. These functions: |
78 | * an error occurs, the 'error' parameter is returned. | 44 | * |
79 | * In single-threaded mode, no storage is allocated. Instead, a pointer | 45 | * _thread_tag_lock: |
80 | * to storage is always returned. | 46 | * lock the mutex associated with the given tag. If the given |
81 | * The 'cleanfn' function of the key structure is called to free the storage. | 47 | * tag is NULL a tag is first allocated. |
82 | * If 'cleanfn' is NULL, then free() is used. This hook can be useful for | 48 | * |
83 | * getting rid of memory leaks. | 49 | * _thread_tag_unlock: |
50 | * unlock the mutex associated with the given tag. If the given | ||
51 | * tag is NULL a tag is first allocated. | ||
52 | * | ||
53 | * _thread_tag_storage: | ||
54 | * return a pointer to per thread instance of data associated | ||
55 | * with the given tag. If the given tag is NULL a tag is first | ||
56 | * allocated. | ||
84 | */ | 57 | */ |
85 | #define _THREAD_PRIVATE(keyname, storage, error) \ | 58 | void _thread_tag_lock(void **); |
86 | _libc_private_storage(&__THREAD_KEY_NAME(keyname), \ | 59 | void _thread_tag_unlock(void **); |
87 | &(storage), sizeof (storage), error) | 60 | void *_thread_tag_storage(void **, void *, size_t, void *); |
88 | 61 | ||
89 | /* | 62 | /* |
90 | * Keys used to access the per thread instances of resolver global data. | 63 | * Macros used in libc to access thread mutex, keys, and per thread storage. |
91 | * These are not static as they are referenced in several places. | 64 | * _THREAD_PRIVATE_KEY and _THREAD_PRIVATE_MUTEX are different macros for |
65 | * historical reasons. They do the same thing, define a static variable | ||
66 | * keyed by 'name' that identifies a mutex and a key to identify per thread | ||
67 | * data. | ||
92 | */ | 68 | */ |
93 | extern volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res); | 69 | #define _THREAD_PRIVATE_KEY(name) \ |
94 | #ifdef INET6 | 70 | static void *__THREAD_NAME(name) |
95 | extern volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res_ext); | 71 | #define _THREAD_PRIVATE_MUTEX(name) \ |
96 | #endif | 72 | static void *__THREAD_NAME(name) |
73 | #define _THREAD_PRIVATE_MUTEX_LOCK(name) \ | ||
74 | _thread_tag_lock(&(__THREAD_NAME(name))) | ||
75 | #define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \ | ||
76 | _thread_tag_unlock(&(__THREAD_NAME(name))) | ||
77 | #define _THREAD_PRIVATE(keyname, storage, error) \ | ||
78 | _thread_tag_storage(&(__THREAD_NAME(keyname)), &(storage), \ | ||
79 | sizeof (storage), error) | ||
80 | /* | ||
81 | * Resolver code is special cased in that it uses global keys. | ||
82 | */ | ||
83 | extern void *__THREAD_NAME(_res); | ||
84 | extern void *__THREAD_NAME(_res_ext); | ||
85 | extern void *__THREAD_NAME(serv_mutex); | ||
97 | 86 | ||
98 | /* | 87 | /* |
99 | * File descriptor locking definitions. | 88 | * File descriptor locking definitions. |
100 | */ | 89 | */ |
101 | #define FD_READ 0x1 | 90 | #define FD_READ 0x1 |
102 | #define FD_WRITE 0x2 | 91 | #define FD_WRITE 0x2 |
103 | #define FD_RDWR (FD_READ | FD_WRITE) | 92 | #define FD_RDWR (FD_READ | FD_WRITE) |
93 | |||
94 | int _thread_fd_lock(int, int, struct timespec *); | ||
95 | void _thread_fd_unlock(int, int); | ||
104 | 96 | ||
105 | #define _FD_LOCK(_fd,_type,_ts) \ | 97 | /* |
106 | _thread_fd_lock(_fd, _type, _ts, __FILE__, __LINE__) | 98 | * Macros are used in libc code for historical (debug) reasons. |
107 | #define _FD_UNLOCK(_fd,_type) \ | 99 | * Define them here. |
108 | _thread_fd_unlock(_fd, _type, __FILE__, __LINE__) | 100 | */ |
101 | #define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts) | ||
102 | #define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type) | ||
109 | 103 | ||
110 | int _thread_fd_lock(int, int, struct timespec *, const char *, int); | ||
111 | void _thread_fd_unlock(int, int, const char *, int); | ||
112 | 104 | ||
113 | /* | 105 | /* |
114 | * malloc lock/unlock definitions | 106 | * malloc lock/unlock prototypes and definitions |
115 | */ | 107 | */ |
116 | # define _MALLOC_LOCK() do { \ | 108 | void _thread_malloc_init(void); |
109 | void _thread_malloc_lock(void); | ||
110 | void _thread_malloc_unlock(void); | ||
111 | |||
112 | #define _MALLOC_LOCK() do { \ | ||
117 | if (__isthreaded) \ | 113 | if (__isthreaded) \ |
118 | _thread_malloc_lock(); \ | 114 | _thread_malloc_lock(); \ |
119 | } while (0) | 115 | } while (0) |
120 | # define _MALLOC_UNLOCK() do { \ | 116 | #define _MALLOC_UNLOCK() do { \ |
121 | if (__isthreaded) \ | 117 | if (__isthreaded) \ |
122 | _thread_malloc_unlock();\ | 118 | _thread_malloc_unlock();\ |
123 | } while (0) | 119 | } while (0) |
124 | # define _MALLOC_LOCK_INIT()do { \ | 120 | #define _MALLOC_LOCK_INIT() do { \ |
125 | if (__isthreaded) \ | 121 | if (__isthreaded) \ |
126 | _thread_malloc_init();\ | 122 | _thread_malloc_init();\ |
127 | } while (0) | 123 | } while (0) |
128 | 124 | ||
129 | 125 | ||
130 | void _thread_malloc_init(void); | ||
131 | void _thread_malloc_lock(void); | ||
132 | void _thread_malloc_unlock(void); | ||
133 | |||
134 | #endif /* _THREAD_PRIVATE_H_ */ | 126 | #endif /* _THREAD_PRIVATE_H_ */ |
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c index 8fb8975ad8..3db8cc82ee 100644 --- a/src/lib/libc/net/getaddrinfo.c +++ b/src/lib/libc/net/getaddrinfo.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getaddrinfo.c,v 1.49 2004/04/14 07:06:15 itojun Exp $ */ | 1 | /* $OpenBSD: getaddrinfo.c,v 1.50 2004/06/07 21:11:23 marc Exp $ */ |
2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ | 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -873,7 +873,7 @@ get_port(ai, servname, matchonly) | |||
873 | int port; | 873 | int port; |
874 | int allownumeric; | 874 | int allownumeric; |
875 | /* mutex is defined in getnameinfo.c */ | 875 | /* mutex is defined in getnameinfo.c */ |
876 | extern pthread_mutex_t __THREAD_MUTEX_NAME(serv_mutex); | 876 | extern void *__THREAD_NAME(serv_mutex); |
877 | 877 | ||
878 | if (servname == NULL) | 878 | if (servname == NULL) |
879 | return 0; | 879 | return 0; |
diff --git a/src/lib/libc/net/getnameinfo.c b/src/lib/libc/net/getnameinfo.c index da5df507ab..62760e178d 100644 --- a/src/lib/libc/net/getnameinfo.c +++ b/src/lib/libc/net/getnameinfo.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getnameinfo.c,v 1.27 2003/07/21 23:17:53 marc Exp $ */ | 1 | /* $OpenBSD: getnameinfo.c,v 1.28 2004/06/07 21:11:23 marc Exp $ */ |
2 | /* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ | 2 | /* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -91,7 +91,7 @@ static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int); | |||
91 | /* | 91 | /* |
92 | * this mutex is also used by get_port in getaddrinfo.c | 92 | * this mutex is also used by get_port in getaddrinfo.c |
93 | */ | 93 | */ |
94 | pthread_mutex_t __THREAD_MUTEX_NAME(serv_mutex) = PTHREAD_MUTEX_INITIALIZER; | 94 | void *__THREAD_NAME(serv_mutex); |
95 | 95 | ||
96 | int | 96 | int |
97 | getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) | 97 | getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) |
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c index 9c73958883..79ccada6ee 100644 --- a/src/lib/libc/net/res_init.c +++ b/src/lib/libc/net/res_init.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: res_init.c,v 1.29 2003/06/02 20:18:36 millert Exp $ */ | 1 | /* $OpenBSD: res_init.c,v 1.30 2004/06/07 21:11:23 marc Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * ++Copyright++ 1985, 1989, 1993 | 4 | * ++Copyright++ 1985, 1989, 1993 |
@@ -60,7 +60,7 @@ | |||
60 | static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; | 60 | static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; |
61 | static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; | 61 | static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; |
62 | #else | 62 | #else |
63 | static char rcsid[] = "$OpenBSD: res_init.c,v 1.29 2003/06/02 20:18:36 millert Exp $"; | 63 | static char rcsid[] = "$OpenBSD: res_init.c,v 1.30 2004/06/07 21:11:23 marc Exp $"; |
64 | #endif | 64 | #endif |
65 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
66 | 66 | ||
@@ -118,9 +118,7 @@ static u_int32_t net_mask(struct in_addr); | |||
118 | /* | 118 | /* |
119 | * Resolver state default settings. | 119 | * Resolver state default settings. |
120 | */ | 120 | */ |
121 | volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res) = { | 121 | void *__THREAD_NAME(_res); |
122 | PTHREAD_ONCE_INIT, 0 | ||
123 | }; | ||
124 | 122 | ||
125 | struct __res_state _res | 123 | struct __res_state _res |
126 | # if defined(__BIND_RES_TEXT) | 124 | # if defined(__BIND_RES_TEXT) |
@@ -128,9 +126,7 @@ struct __res_state _res | |||
128 | # endif | 126 | # endif |
129 | ; | 127 | ; |
130 | #ifdef INET6 | 128 | #ifdef INET6 |
131 | volatile struct _thread_private_key_struct __THREAD_KEY_NAME(_res_ext) = { | 129 | void *__THREAD_NAME(_res_ext); |
132 | PTHREAD_ONCE_INIT, 0 | ||
133 | }; | ||
134 | 130 | ||
135 | struct __res_state_ext _res_ext; | 131 | struct __res_state_ext _res_ext; |
136 | #endif /* INET6 */ | 132 | #endif /* INET6 */ |