diff options
author | kurt <> | 2007-06-05 18:11:48 +0000 |
---|---|---|
committer | kurt <> | 2007-06-05 18:11:48 +0000 |
commit | a9f7df88bc0ab9f89af4f9e71a3e4daea3a14008 (patch) | |
tree | 2067279e11369f87053dd823e5056056cdbe01a3 /src/lib | |
parent | c077683d6b12ed7a0bd8ef024abfedf5970eee5b (diff) | |
download | openbsd-a9f7df88bc0ab9f89af4f9e71a3e4daea3a14008.tar.gz openbsd-a9f7df88bc0ab9f89af4f9e71a3e4daea3a14008.tar.bz2 openbsd-a9f7df88bc0ab9f89af4f9e71a3e4daea3a14008.zip |
_FD_LOCK/UNLOCK() is libpthread specific and not needed for librthread, so
isolate its usage to libpthread only and replace with generic non-static
mutex support in the one place it is needed:
- remove _FD_LOCK/UNLOCK from lseek and ftruncate in libc and make the
functions weak so that libpthread can override with its own new
versions that do the locking.
- remove _thread_fd_lock/unlock() weak functions from libc and adjust
libpthread for the change.
- add generic _thread_mutex_lock/unlock/destroy() weak functions in libc
to support non-static mutexes in libc and add libpthread and librthread
implementations for them. libc can utilize non-static mutexes via the
new _MUTEX_LOCK/UNLOCK/DESTROY() macros. Actually these new macros can
support both static and non-static mutexes but currently only using
them for non-static.
- make opendir/closedir/readdir/readdir_r/seekdir/telldir() thread-safe
for both thread libraries by using a non-static mutex in the struct
_dirdesc (typedef DIR), utilizing it in the *dir functions and remove
remaining and incorrect _FD_LOCK/UNLOCK() use in libc.
- add comments to both thread libraries to indicate libc depends on the
current implementation of static mutex initialization. suggested by
marc@
- major bump libc and libpthread due to function removal, structure
change and weak symbol conversions.
okay marc@, tedu@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/include/thread_private.h | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h index c5acc4b5e4..a365c25e66 100644 --- a/src/lib/libc/include/thread_private.h +++ b/src/lib/libc/include/thread_private.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: thread_private.h,v 1.19 2006/09/26 14:18:28 kurt Exp $ */ | 1 | /* $OpenBSD: thread_private.h,v 1.20 2007/06/05 18:11:48 kurt Exp $ */ |
2 | 2 | ||
3 | /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ | 3 | /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ |
4 | 4 | ||
@@ -54,10 +54,24 @@ extern int __isthreaded; | |||
54 | * return a pointer to per thread instance of data associated | 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 | 55 | * with the given tag. If the given tag is NULL a tag is first |
56 | * allocated. | 56 | * allocated. |
57 | * | ||
58 | * _thread_mutex_lock: | ||
59 | * lock the given mutex. If the given mutex is NULL, | ||
60 | * rely on rthreads/pthreads implementation to initialize | ||
61 | * the mutex before locking. | ||
62 | * | ||
63 | * _thread_mutex_unlock: | ||
64 | * unlock the given mutex. | ||
65 | * | ||
66 | * _thread_mutex_destroy: | ||
67 | * destroy the given mutex. | ||
57 | */ | 68 | */ |
58 | void _thread_tag_lock(void **); | 69 | void _thread_tag_lock(void **); |
59 | void _thread_tag_unlock(void **); | 70 | void _thread_tag_unlock(void **); |
60 | void *_thread_tag_storage(void **, void *, size_t, void *); | 71 | void *_thread_tag_storage(void **, void *, size_t, void *); |
72 | void _thread_mutex_lock(void **); | ||
73 | void _thread_mutex_unlock(void **); | ||
74 | void _thread_mutex_destroy(void **); | ||
61 | 75 | ||
62 | /* | 76 | /* |
63 | * Macros used in libc to access thread mutex, keys, and per thread storage. | 77 | * Macros used in libc to access thread mutex, keys, and per thread storage. |
@@ -77,32 +91,32 @@ void *_thread_tag_storage(void **, void *, size_t, void *); | |||
77 | #define _THREAD_PRIVATE(keyname, storage, error) \ | 91 | #define _THREAD_PRIVATE(keyname, storage, error) \ |
78 | _thread_tag_storage(&(__THREAD_NAME(keyname)), &(storage), \ | 92 | _thread_tag_storage(&(__THREAD_NAME(keyname)), &(storage), \ |
79 | sizeof (storage), error) | 93 | 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); | ||
86 | 94 | ||
87 | /* | 95 | /* |
88 | * File descriptor locking definitions. | 96 | * Macros used in libc to access non-static mutexes. |
89 | */ | 97 | */ |
90 | #define FD_READ 0x1 | 98 | #define _MUTEX_LOCK(mutex) \ |
91 | #define FD_WRITE 0x2 | 99 | do { \ |
92 | #define FD_RDWR (FD_READ | FD_WRITE) | 100 | if (__isthreaded) \ |
93 | #define FD_RDWR_CLOSE (FD_RDWR | 0x4) | 101 | _thread_mutex_lock(mutex); \ |
94 | 102 | } while (0) | |
95 | struct timespec; | 103 | #define _MUTEX_UNLOCK(mutex) \ |
96 | int _thread_fd_lock(int, int, struct timespec *); | 104 | do { \ |
97 | void _thread_fd_unlock(int, int); | 105 | if (__isthreaded) \ |
106 | _thread_mutex_unlock(mutex); \ | ||
107 | } while (0) | ||
108 | #define _MUTEX_DESTROY(mutex) \ | ||
109 | do { \ | ||
110 | if (__isthreaded) \ | ||
111 | _thread_mutex_destroy(mutex); \ | ||
112 | } while (0) | ||
98 | 113 | ||
99 | /* | 114 | /* |
100 | * Macros are used in libc code for historical (debug) reasons. | 115 | * Resolver code is special cased in that it uses global keys. |
101 | * Define them here. | ||
102 | */ | 116 | */ |
103 | #define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts) | 117 | extern void *__THREAD_NAME(_res); |
104 | #define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type) | 118 | extern void *__THREAD_NAME(_res_ext); |
105 | 119 | extern void *__THREAD_NAME(serv_mutex); | |
106 | 120 | ||
107 | /* | 121 | /* |
108 | * malloc lock/unlock prototypes and definitions | 122 | * malloc lock/unlock prototypes and definitions |