diff options
author | Kurt Miller <kurt@cvs.openbsd.org> | 2007-06-05 18:11:50 +0000 |
---|---|---|
committer | Kurt Miller <kurt@cvs.openbsd.org> | 2007-06-05 18:11:50 +0000 |
commit | 5ea227edb4b41ecee104b943846b3df89ceafb8c (patch) | |
tree | 5e3932033b9b169395a0474156a37318fa74db42 /lib/libc/include | |
parent | 5727900f0e332290d68166eab7d4e4d71eea2264 (diff) |
_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 'lib/libc/include')
-rw-r--r-- | lib/libc/include/thread_private.h | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/lib/libc/include/thread_private.h b/lib/libc/include/thread_private.h index c5acc4b5e43..a365c25e66a 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.19 2006/09/26 14:18:28 kurt Exp $ */ +/* $OpenBSD: thread_private.h,v 1.20 2007/06/05 18:11:48 kurt Exp $ */ /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ @@ -54,10 +54,24 @@ extern int __isthreaded; * 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. + * + * _thread_mutex_lock: + * lock the given mutex. If the given mutex is NULL, + * rely on rthreads/pthreads implementation to initialize + * the mutex before locking. + * + * _thread_mutex_unlock: + * unlock the given mutex. + * + * _thread_mutex_destroy: + * destroy the given mutex. */ void _thread_tag_lock(void **); void _thread_tag_unlock(void **); void *_thread_tag_storage(void **, void *, size_t, void *); +void _thread_mutex_lock(void **); +void _thread_mutex_unlock(void **); +void _thread_mutex_destroy(void **); /* * 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 *); #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. + * Macros used in libc to access non-static mutexes. */ -#define FD_READ 0x1 -#define FD_WRITE 0x2 -#define FD_RDWR (FD_READ | FD_WRITE) -#define FD_RDWR_CLOSE (FD_RDWR | 0x4) - -struct timespec; -int _thread_fd_lock(int, int, struct timespec *); -void _thread_fd_unlock(int, int); +#define _MUTEX_LOCK(mutex) \ + do { \ + if (__isthreaded) \ + _thread_mutex_lock(mutex); \ + } while (0) +#define _MUTEX_UNLOCK(mutex) \ + do { \ + if (__isthreaded) \ + _thread_mutex_unlock(mutex); \ + } while (0) +#define _MUTEX_DESTROY(mutex) \ + do { \ + if (__isthreaded) \ + _thread_mutex_destroy(mutex); \ + } while (0) /* - * Macros are used in libc code for historical (debug) reasons. - * Define them here. + * Resolver code is special cased in that it uses global keys. */ -#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts) -#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type) - +extern void *__THREAD_NAME(_res); +extern void *__THREAD_NAME(_res_ext); +extern void *__THREAD_NAME(serv_mutex); /* * malloc lock/unlock prototypes and definitions |