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/libpthread/uthread | |
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/libpthread/uthread')
-rw-r--r-- | lib/libpthread/uthread/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libpthread/uthread/pthread_private.h | 13 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_ftruncate.c | 57 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_init.c | 11 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_lseek.c | 56 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_mutex.c | 6 |
6 files changed, 138 insertions, 9 deletions
diff --git a/lib/libpthread/uthread/Makefile.inc b/lib/libpthread/uthread/Makefile.inc index 6ef4e88c344..3e814dd0500 100644 --- a/lib/libpthread/uthread/Makefile.inc +++ b/lib/libpthread/uthread/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.19 2005/10/30 03:37:34 brad Exp $ +# $OpenBSD: Makefile.inc,v 1.20 2007/06/05 18:11:48 kurt Exp $ # $FreeBSD: Makefile.inc,v 1.19 1999/08/28 00:03:19 peter Exp $ # uthread sources @@ -59,6 +59,7 @@ SRCS+= \ uthread_fstat.c \ uthread_fstatfs.c \ uthread_fsync.c \ + uthread_ftruncate.c \ uthread_gc.c \ uthread_getdirentries.c \ uthread_getpeername.c \ @@ -75,6 +76,7 @@ SRCS+= \ uthread_kqueue.c \ uthread_kill.c \ uthread_listen.c \ + uthread_lseek.c \ uthread_main_np.c \ uthread_mattr_init.c \ uthread_mattr_kind_np.c \ diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h index 5ccdde97165..d26fc50bf53 100644 --- a/lib/libpthread/uthread/pthread_private.h +++ b/lib/libpthread/uthread/pthread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pthread_private.h,v 1.66 2007/05/21 16:50:36 kurt Exp $ */ +/* $OpenBSD: pthread_private.h,v 1.67 2007/06/05 18:11:49 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -491,8 +491,15 @@ enum pthread_state { /* - * File descriptor locking definitions are defined in "thread_private.h" + * File descriptor locking definitions. */ +#define FD_READ 0x1 +#define FD_WRITE 0x2 +#define FD_RDWR (FD_READ | FD_WRITE) +#define FD_RDWR_CLOSE (FD_RDWR | 0x4) + +#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts) +#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type) /* * File status flags struture - shared for dup'ed fd's @@ -1148,6 +1155,8 @@ void _thread_cleanupspecific(void); void _thread_clear_pending(int, pthread_t); void _thread_dump_data(const void *, int); void _thread_dump_info(void); +int _thread_fd_lock(int, int, struct timespec *); +void _thread_fd_unlock(int, int); void _thread_init(void); void _thread_kern_lock(int); void _thread_kern_sched(struct sigcontext *); diff --git a/lib/libpthread/uthread/uthread_ftruncate.c b/lib/libpthread/uthread/uthread_ftruncate.c new file mode 100644 index 00000000000..c29e2f090dc --- /dev/null +++ b/lib/libpthread/uthread/uthread_ftruncate.c @@ -0,0 +1,57 @@ +/* $OpenBSD: uthread_ftruncate.c,v 1.1 2007/06/05 18:11:49 kurt Exp $ */ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +register_t __syscall(quad_t, ...); + +/* + * 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) +{ + 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; +} +#endif diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c index 55fed967e2d..93f7ec27ad6 100644 --- a/lib/libpthread/uthread/uthread_init.c +++ b/lib/libpthread/uthread/uthread_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_init.c,v 1.38 2007/05/21 16:50:36 kurt Exp $ */ +/* $OpenBSD: uthread_init.c,v 1.39 2007/06/05 18:11:49 kurt Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -130,8 +130,6 @@ static void *references[] = { &write, &writev, /* libc thread-safe helper functions */ - &_thread_fd_lock, - &_thread_fd_unlock, &_thread_malloc_init, &_thread_malloc_lock, &_thread_malloc_unlock, @@ -140,9 +138,14 @@ static void *references[] = { &_thread_tag_lock, &_thread_tag_unlock, &_thread_tag_storage, + &_thread_mutex_lock, + &_thread_mutex_unlock, + &_thread_mutex_destroy, &flockfile, + &ftruncate, &ftrylockfile, - &funlockfile + &funlockfile, + &lseek }; /* diff --git a/lib/libpthread/uthread/uthread_lseek.c b/lib/libpthread/uthread/uthread_lseek.c new file mode 100644 index 00000000000..152d707938b --- /dev/null +++ b/lib/libpthread/uthread/uthread_lseek.c @@ -0,0 +1,56 @@ +/* $OpenBSD: uthread_lseek.c,v 1.1 2007/06/05 18:11:49 kurt Exp $ */ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <unistd.h> +#include <sys/syscall.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +off_t __syscall(quad_t, ...); + +/* + * 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) +{ + 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; +} +#endif diff --git a/lib/libpthread/uthread/uthread_mutex.c b/lib/libpthread/uthread/uthread_mutex.c index a237d193070..f45a0f64616 100644 --- a/lib/libpthread/uthread/uthread_mutex.c +++ b/lib/libpthread/uthread/uthread_mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_mutex.c,v 1.20 2007/05/01 18:16:38 kurt Exp $ */ +/* $OpenBSD: uthread_mutex.c,v 1.21 2007/06/05 18:11:49 kurt Exp $ */ /* * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -667,7 +667,9 @@ pthread_mutex_lock(pthread_mutex_t *mutex) /* * If the mutex is statically initialized, perform the dynamic - * initialization: + * initialization. Note: _thread_mutex_lock() in libc requires + * pthread_mutex_lock() to perform the mutex init when *mutex + * is NULL. */ else if ((*mutex != NULL) || ((ret = init_static(mutex)) == 0)) ret = mutex_lock_common(mutex); |