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/sys | |
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/sys')
-rw-r--r-- | lib/libc/sys/ftruncate.c | 21 | ||||
-rw-r--r-- | lib/libc/sys/lseek.c | 21 |
2 files changed, 18 insertions, 24 deletions
diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c index c1722580859..d0f5e9837c4 100644 --- a/lib/libc/sys/ftruncate.c +++ b/lib/libc/sys/ftruncate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftruncate.c,v 1.14 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: ftruncate.c,v 1.15 2007/06/05 18:11:48 kurt Exp $ */ /* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -28,27 +28,24 @@ * SUCH DAMAGE. */ -#include <sys/types.h> #include <sys/syscall.h> #include <unistd.h> #include "thread_private.h" register_t __syscall(quad_t, ...); +/* ftruncate is weak to support libpthread locking */ + +WEAK_PROTOTYPE(ftruncate); + +WEAK_ALIAS(ftruncate); + /* * This function provides 64-bit offset padding that * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ int -ftruncate(int fd, off_t length) +WEAK_NAME(ftruncate)(int fd, off_t length) { - int retval; - - if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) { - retval = -1; - } else { - retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length); - _FD_UNLOCK(fd, FD_RDWR); - } - return retval; + return (__syscall((quad_t)SYS_ftruncate, fd, 0, length)); } diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c index f9e9ef98aa3..1abb688a348 100644 --- a/lib/libc/sys/lseek.c +++ b/lib/libc/sys/lseek.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lseek.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: lseek.c,v 1.14 2007/06/05 18:11:48 kurt Exp $ */ /* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -28,27 +28,24 @@ * SUCH DAMAGE. */ -#include <sys/types.h> #include <sys/syscall.h> #include <unistd.h> #include "thread_private.h" off_t __syscall(quad_t, ...); +/* lseek is weak to support libpthread locking */ + +WEAK_PROTOTYPE(lseek); + +WEAK_ALIAS(lseek); + /* * This function provides 64-bit offset padding that * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ off_t -lseek(int fd, off_t offset, int whence) +WEAK_NAME(lseek)(int fd, off_t offset, int whence) { - off_t retval; - - if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) { - retval = -1; - } else { - retval = __syscall((quad_t)SYS_lseek, fd, 0, offset, whence); - _FD_UNLOCK(fd, FD_RDWR); - } - return retval; + return (__syscall((quad_t)SYS_lseek, fd, 0, offset, whence)); } |