diff options
author | jasone <jasone@FreeBSD.org> | 2000-01-27 23:07:25 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 2000-01-27 23:07:25 +0000 |
commit | 8abe2a2d86ee5f72093b3feeabf05c9f6f963576 (patch) | |
tree | 2ebe01199c17764ebcd26435b5ce1c06ebb67ad5 /lib/libpthread/thread | |
parent | 1731b249ccd9d7586d511eda8756f5c6b57b871c (diff) | |
download | FreeBSD-src-8abe2a2d86ee5f72093b3feeabf05c9f6f963576.zip FreeBSD-src-8abe2a2d86ee5f72093b3feeabf05c9f6f963576.tar.gz |
Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),
just use _foo() <-- foo(). In the case of a libpthread that doesn't do
call conversion (such as linuxthreads and our upcoming libpthread), this
is adequate. In the case of libc_r, we still need three names, which are
now _thread_sys_foo() <-- _foo() <-- foo().
Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(),
nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo().
Remove all internal libc usage of: creat(), pause(), sleep(), system(),
tcdrain(), wait(), and waitpid().
Make thread cancellation fully POSIX-compliant.
Suggested by: deischen
Diffstat (limited to 'lib/libpthread/thread')
32 files changed, 570 insertions, 80 deletions
diff --git a/lib/libpthread/thread/Makefile.inc b/lib/libpthread/thread/Makefile.inc index 2a13365..a88f955 100644 --- a/lib/libpthread/thread/Makefile.inc +++ b/lib/libpthread/thread/Makefile.inc @@ -5,6 +5,7 @@ SRCS+= \ uthread_accept.c \ + uthread_aio_suspend.c \ uthread_attr_destroy.c \ uthread_attr_init.c \ uthread_attr_getdetachstate.c \ @@ -31,6 +32,7 @@ SRCS+= \ uthread_condattr_destroy.c \ uthread_condattr_init.c \ uthread_connect.c \ + uthread_creat.c \ uthread_create.c \ uthread_detach.c \ uthread_dup.c \ @@ -76,6 +78,7 @@ SRCS+= \ uthread_nanosleep.c \ uthread_once.c \ uthread_open.c \ + uthread_pause.c \ uthread_pipe.c \ uthread_poll.c \ uthread_priority_queue.c \ @@ -106,14 +109,19 @@ SRCS+= \ uthread_sigsuspend.c \ uthread_sigwait.c \ uthread_single_np.c \ + uthread_sleep.c \ uthread_socket.c \ uthread_socketpair.c \ uthread_spec.c \ uthread_spinlock.c \ uthread_suspend_np.c \ uthread_switch_np.c \ + uthread_system.c \ + uthread_tcdrain.c \ uthread_vfork.c \ + uthread_wait.c \ uthread_wait4.c \ + uthread_waitpid.c \ uthread_write.c \ uthread_writev.c \ uthread_yield.c diff --git a/lib/libpthread/thread/thr_aio_suspend.c b/lib/libpthread/thread/thr_aio_suspend.c new file mode 100644 index 0000000..3bc373a --- /dev/null +++ b/lib/libpthread/thread/thr_aio_suspend.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2000 Jason Evans <jasone@canonware.com>. + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD$ + */ + +#include <aio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +int +_aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct + timespec *timeout) +{ + int ret; + + _thread_enter_cancellation_point(); + ret = _aio_suspend(iocbs, niocb, timeout); + _thread_leave_cancellation_point(); + + return ret; +} + +__weak_reference(_aio_suspend, aio_suspend); +#endif diff --git a/lib/libpthread/thread/thr_close.c b/lib/libpthread/thread/thr_close.c index fe2d9e2..9dee2bc 100644 --- a/lib/libpthread/thread/thr_close.c +++ b/lib/libpthread/thread/thr_close.c @@ -41,15 +41,13 @@ #include "pthread_private.h" int -_libc_close(int fd) +_close(int fd) { int flags; int ret; struct stat sb; struct fd_table_entry *entry; - _thread_enter_cancellation_point(); - if ((fd == _thread_kern_pipe[0]) || (fd == _thread_kern_pipe[1])) { /* * Don't allow silly programs to close the kernel pipe. @@ -99,9 +97,18 @@ _libc_close(int fd) /* Close the file descriptor: */ ret = _thread_sys_close(fd); } - _thread_leave_cancellation_point(); return (ret); } -__weak_reference(_libc_close, close); +int +close(int fd) +{ + int ret; + + _thread_enter_cancellation_point(); + ret = _close(fd); + _thread_leave_cancellation_point(); + + return ret; +} #endif diff --git a/lib/libpthread/thread/thr_cond.c b/lib/libpthread/thread/thr_cond.c index ced48e3..d236607 100644 --- a/lib/libpthread/thread/thr_cond.c +++ b/lib/libpthread/thread/thr_cond.c @@ -160,6 +160,8 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) int rval = 0; int interrupted = 0; + _thread_enter_cancellation_point(); + if (cond == NULL) rval = EINVAL; @@ -286,6 +288,8 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) _thread_leave_cancellation_point(); } + _thread_leave_cancellation_point(); + /* Return the completion status: */ return (rval); } @@ -297,12 +301,15 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, int rval = 0; int interrupted = 0; + _thread_enter_cancellation_point(); + if (cond == NULL || abstime == NULL) rval = EINVAL; if (abstime->tv_sec < 0 || abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) { errno = EINVAL; + _thread_leave_cancellation_point(); return (-1); } @@ -448,6 +455,8 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, _thread_leave_cancellation_point(); } + _thread_leave_cancellation_point(); + /* Return the completion status: */ return (rval); } diff --git a/lib/libpthread/thread/thr_creat.c b/lib/libpthread/thread/thr_creat.c new file mode 100644 index 0000000..bb8e7c2 --- /dev/null +++ b/lib/libpthread/thread/thr_creat.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2000 Jason Evans <jasone@canonware.com>. + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD$ + */ + +#include <fcntl.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +int +creat(const char *path, mode_t mode) +{ + int ret; + + _thread_enter_cancellation_point(); + ret = __creat(path, mode); + _thread_leave_cancellation_point(); + + return ret; +} +#endif diff --git a/lib/libpthread/thread/thr_exit.c b/lib/libpthread/thread/thr_exit.c index 57ac114..22e2ce8 100644 --- a/lib/libpthread/thread/thr_exit.c +++ b/lib/libpthread/thread/thr_exit.c @@ -41,7 +41,7 @@ #include <pthread.h> #include "pthread_private.h" -void _libc__exit(int status) +void __exit(int status) { int flags; int i; @@ -77,7 +77,7 @@ void _libc__exit(int status) _thread_sys__exit(status); } -__weak_reference(_libc__exit, _exit); +__weak_reference(__exit, _exit); void _thread_exit(char *fname, int lineno, char *string) diff --git a/lib/libpthread/thread/thr_fcntl.c b/lib/libpthread/thread/thr_fcntl.c index 6cd2b12..06e2e3b 100644 --- a/lib/libpthread/thread/thr_fcntl.c +++ b/lib/libpthread/thread/thr_fcntl.c @@ -39,7 +39,7 @@ #include "pthread_private.h" int -_libc_fcntl(int fd, int cmd,...) +_fcntl(int fd, int cmd,...) { int flags = 0; int nonblock; @@ -47,8 +47,6 @@ _libc_fcntl(int fd, int cmd,...) int ret; va_list ap; - _thread_enter_cancellation_point(); - /* Lock the file descriptor: */ if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { /* Initialise the variable argument list: */ @@ -137,11 +135,36 @@ _libc_fcntl(int fd, int cmd,...) /* Unlock the file descriptor: */ _FD_UNLOCK(fd, FD_RDWR); } - _thread_leave_cancellation_point(); - /* Return the completion status: */ return (ret); } -__weak_reference(_libc_fcntl, fcntl); +int +fcntl(int fd, int cmd,...) +{ + int ret; + va_list ap; + + _thread_enter_cancellation_point(); + + va_start(ap, cmd); + switch (cmd) { + case F_DUPFD: + case F_SETFD: + case F_SETFL: + ret = fcntl(fd, cmd, va_arg(ap, int)); + break; + case F_GETFD: + case F_GETFL: + ret = fcntl(fd, cmd); + break; + default: + ret = fcntl(fd, cmd, va_arg(ap, void *)); + } + va_end(ap); + + _thread_leave_cancellation_point(); + + return ret; +} #endif diff --git a/lib/libpthread/thread/thr_fork.c b/lib/libpthread/thread/thr_fork.c index 8c112e8..88f1c43 100644 --- a/lib/libpthread/thread/thr_fork.c +++ b/lib/libpthread/thread/thr_fork.c @@ -41,7 +41,7 @@ #include "pthread_private.h" pid_t -_libc_fork(void) +_fork(void) { int i, flags; pid_t ret; @@ -221,5 +221,5 @@ _libc_fork(void) return (ret); } -__weak_reference(_libc_fork, fork); +__weak_reference(_fork, fork); #endif diff --git a/lib/libpthread/thread/thr_fsync.c b/lib/libpthread/thread/thr_fsync.c index 048e60b..0d88320 100644 --- a/lib/libpthread/thread/thr_fsync.c +++ b/lib/libpthread/thread/thr_fsync.c @@ -37,18 +37,26 @@ #include "pthread_private.h" int -_libc_fsync(int fd) +_fsync(int fd) { - int ret; + int ret; - _thread_enter_cancellation_point(); if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { ret = _thread_sys_fsync(fd); _FD_UNLOCK(fd, FD_RDWR); } - _thread_leave_cancellation_point(); return (ret); } -__weak_reference(_libc_fsync, fsync); +int +fsync(int fd) +{ + int ret; + + _thread_enter_cancellation_point(); + ret = _fsync(fd); + _thread_leave_cancellation_point(); + + return ret; +} #endif diff --git a/lib/libpthread/thread/thr_msync.c b/lib/libpthread/thread/thr_msync.c index 9559ec4..2ae6ac7 100644 --- a/lib/libpthread/thread/thr_msync.c +++ b/lib/libpthread/thread/thr_msync.c @@ -13,30 +13,30 @@ #include "pthread_private.h" int -_libc_msync(addr, len, flags) - void *addr; - size_t len; - int flags; +_msync(void *addr, size_t len, int flags) { int ret; + ret = _thread_sys_msync(addr, len, flags); + + return (ret); +} + +int +msync(void *addr, size_t len, int flags) +{ + int ret; + /* * XXX This is quite pointless unless we know how to get the * file descriptor associated with the memory, and lock it for * write. The only real use of this wrapper is to guarantee * a cancellation point, as per the standard. sigh. */ - - /* This is a cancellation point: */ _thread_enter_cancellation_point(); - - ret = _thread_sys_msync(addr, len, flags); - - /* No longer in a cancellation point: */ + ret = _msync(addr, len, flags); _thread_leave_cancellation_point(); - return (ret); + return ret; } - -__weak_reference(_libc_msync, msync); #endif diff --git a/lib/libpthread/thread/thr_nanosleep.c b/lib/libpthread/thread/thr_nanosleep.c index e9052f9..3bbc9a6 100644 --- a/lib/libpthread/thread/thr_nanosleep.c +++ b/lib/libpthread/thread/thr_nanosleep.c @@ -38,7 +38,7 @@ #include "pthread_private.h" int -_libc_nanosleep(const struct timespec * time_to_sleep, +_nanosleep(const struct timespec * time_to_sleep, struct timespec * time_remaining) { int ret = 0; @@ -47,7 +47,6 @@ _libc_nanosleep(const struct timespec * time_to_sleep, struct timespec remaining_time; struct timeval tv; - _thread_enter_cancellation_point(); /* Check if the time to sleep is legal: */ if (time_to_sleep == NULL || time_to_sleep->tv_sec < 0 || time_to_sleep->tv_nsec < 0 || time_to_sleep->tv_nsec >= 1000000000) { @@ -117,9 +116,19 @@ _libc_nanosleep(const struct timespec * time_to_sleep, ret = -1; } } - _thread_leave_cancellation_point(); return (ret); } -__weak_reference(_libc_nanosleep, nanosleep); +int +nanosleep(const struct timespec * time_to_sleep, struct timespec * + time_remaining) +{ + int ret; + + _thread_enter_cancellation_point(); + ret = _nanosleep(time_to_sleep, time_remaining); + _thread_leave_cancellation_point(); + + return ret; +} #endif diff --git a/lib/libpthread/thread/thr_open.c b/lib/libpthread/thread/thr_open.c index 4bc2f1a..e7fef91 100644 --- a/lib/libpthread/thread/thr_open.c +++ b/lib/libpthread/thread/thr_open.c @@ -42,14 +42,12 @@ #include "pthread_private.h" int -_libc_open(const char *path, int flags,...) +_open(const char *path, int flags,...) { int fd; int mode = 0; va_list ap; - _thread_enter_cancellation_point(); - /* Check if the file is being created: */ if (flags & O_CREAT) { /* Get the creation mode: */ @@ -69,11 +67,30 @@ _libc_open(const char *path, int flags,...) fd = -1; } - _thread_leave_cancellation_point(); - /* Return the file descriptor or -1 on error: */ return (fd); } -__weak_reference(_libc_open, open); +int +open(const char *path, int flags,...) +{ + int ret; + int mode = 0; + va_list ap; + + _thread_enter_cancellation_point(); + + /* Check if the file is being created: */ + if (flags & O_CREAT) { + /* Get the creation mode: */ + va_start(ap, flags); + mode = va_arg(ap, int); + va_end(ap); + } + + ret = _open(path, flags, mode); + _thread_leave_cancellation_point(); + + return ret; +} #endif diff --git a/lib/libpthread/thread/thr_pause.c b/lib/libpthread/thread/thr_pause.c new file mode 100644 index 0000000..a841556 --- /dev/null +++ b/lib/libpthread/thread/thr_pause.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2000 Jason Evans <jasone@canonware.com>. + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD$ + */ + +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +int +pause(void) +{ + int ret; + + _thread_enter_cancellation_point(); + ret = __pause(); + _thread_leave_cancellation_point(); + + return ret; +} +#endif diff --git a/lib/libpthread/thread/thr_poll.c b/lib/libpthread/thread/thr_poll.c index fb6a266..d395250 100644 --- a/lib/libpthread/thread/thr_poll.c +++ b/lib/libpthread/thread/thr_poll.c @@ -44,7 +44,7 @@ int -_libc_poll(struct pollfd *fds, unsigned int nfds, int timeout) +_poll(struct pollfd *fds, unsigned int nfds, int timeout) { struct timespec ts; int numfds = nfds; @@ -97,5 +97,5 @@ _libc_poll(struct pollfd *fds, unsigned int nfds, int timeout) return (ret); } -__weak_reference(_libc_poll, poll); +__weak_reference(_poll, poll); #endif diff --git a/lib/libpthread/thread/thr_read.c b/lib/libpthread/thread/thr_read.c index ad66df3..b4d9694 100644 --- a/lib/libpthread/thread/thr_read.c +++ b/lib/libpthread/thread/thr_read.c @@ -42,16 +42,13 @@ #include "pthread_private.h" ssize_t -_libc_read(int fd, void *buf, size_t nbytes) +_read(int fd, void *buf, size_t nbytes) { int ret; int type; - _thread_enter_cancellation_point(); - /* POSIX says to do just this: */ if (nbytes == 0) { - _thread_leave_cancellation_point(); return (0); } @@ -65,7 +62,6 @@ _libc_read(int fd, void *buf, size_t nbytes) /* File is not open for read: */ errno = EBADF; _FD_UNLOCK(fd, FD_READ); - _thread_leave_cancellation_point(); return (-1); } @@ -97,9 +93,18 @@ _libc_read(int fd, void *buf, size_t nbytes) } _FD_UNLOCK(fd, FD_READ); } - _thread_leave_cancellation_point(); return (ret); } -__weak_reference(_libc_read, read); +ssize_t +read(int fd, void *buf, size_t nbytes) +{ + ssize_t ret; + + _thread_enter_cancellation_point(); + ret = _read(fd, buf, nbytes); + _thread_leave_cancellation_point(); + + return ret; +} #endif diff --git a/lib/libpthread/thread/thr_readv.c b/lib/libpthread/thread/thr_readv.c index c1965d8..2c66a98 100644 --- a/lib/libpthread/thread/thr_readv.c +++ b/lib/libpthread/thread/thr_readv.c @@ -42,7 +42,7 @@ #include "pthread_private.h" ssize_t -_libc_readv(int fd, const struct iovec * iov, int iovcnt) +_readv(int fd, const struct iovec * iov, int iovcnt) { int ret; int type; @@ -91,5 +91,5 @@ _libc_readv(int fd, const struct iovec * iov, int iovcnt) return (ret); } -__weak_reference(_libc_readv, readv); +__weak_reference(_readv, readv); #endif diff --git a/lib/libpthread/thread/thr_select.c b/lib/libpthread/thread/thr_select.c index a7ceecc..d0e61e2 100644 --- a/lib/libpthread/thread/thr_select.c +++ b/lib/libpthread/thread/thr_select.c @@ -45,8 +45,8 @@ #include "pthread_private.h" int -_libc_select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * - exceptfds, struct timeval * timeout) +_select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, + struct timeval * timeout) { struct timespec ts; int i, ret = 0, f_wait = 1; @@ -204,5 +204,5 @@ _libc_select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * return (ret); } -__weak_reference(_libc_select, select); +__weak_reference(_select, select); #endif diff --git a/lib/libpthread/thread/thr_sem.c b/lib/libpthread/thread/thr_sem.c index 8adb0d4..d35f9bc 100644 --- a/lib/libpthread/thread/thr_sem.c +++ b/lib/libpthread/thread/thr_sem.c @@ -147,6 +147,8 @@ sem_wait(sem_t *sem) { int retval; + _thread_enter_cancellation_point(); + _SEM_CHECK_VALIDITY(sem); pthread_mutex_lock(&(*sem)->lock); @@ -162,6 +164,7 @@ sem_wait(sem_t *sem) retval = 0; RETURN: + _thread_leave_cancellation_point(); return retval; } diff --git a/lib/libpthread/thread/thr_sigaction.c b/lib/libpthread/thread/thr_sigaction.c index f2f7286..e0aa523 100644 --- a/lib/libpthread/thread/thr_sigaction.c +++ b/lib/libpthread/thread/thr_sigaction.c @@ -38,7 +38,7 @@ #include "pthread_private.h" int -_libc_sigaction(int sig, const struct sigaction * act, struct sigaction * oact) +_sigaction(int sig, const struct sigaction * act, struct sigaction * oact) { int ret = 0; struct sigaction gact; @@ -106,5 +106,5 @@ _libc_sigaction(int sig, const struct sigaction * act, struct sigaction * oact) return (ret); } -__weak_reference(_libc_sigaction, sigaction); +__weak_reference(_sigaction, sigaction); #endif diff --git a/lib/libpthread/thread/thr_sigpending.c b/lib/libpthread/thread/thr_sigpending.c index feb4300..a630f0c 100644 --- a/lib/libpthread/thread/thr_sigpending.c +++ b/lib/libpthread/thread/thr_sigpending.c @@ -38,7 +38,7 @@ #include "pthread_private.h" int -_libc_sigpending(sigset_t * set) +_sigpending(sigset_t * set) { int ret = 0; @@ -54,5 +54,5 @@ _libc_sigpending(sigset_t * set) return (ret); } -__weak_reference(_libc_sigpending, sigpending); +__weak_reference(_sigpending, sigpending); #endif diff --git a/lib/libpthread/thread/thr_sigprocmask.c b/lib/libpthread/thread/thr_sigprocmask.c index 28ab4fa..b10089c 100644 --- a/lib/libpthread/thread/thr_sigprocmask.c +++ b/lib/libpthread/thread/thr_sigprocmask.c @@ -41,7 +41,7 @@ #include "pthread_private.h" int -_libc_sigprocmask(int how, const sigset_t * set, sigset_t * oset) +_sigprocmask(int how, const sigset_t * set, sigset_t * oset) { int ret = 0; @@ -90,5 +90,5 @@ _libc_sigprocmask(int how, const sigset_t * set, sigset_t * oset) return (ret); } -__weak_reference(_libc_sigprocmask, sigprocmask); +__weak_reference(_sigprocmask, sigprocmask); #endif diff --git a/lib/libpthread/thread/thr_sigsuspend.c b/lib/libpthread/thread/thr_sigsuspend.c index b64897a..28959c8 100644 --- a/lib/libpthread/thread/thr_sigsuspend.c +++ b/lib/libpthread/thread/thr_sigsuspend.c @@ -38,7 +38,7 @@ #include "pthread_private.h" int -_libc_sigsuspend(const sigset_t * set) +_sigsuspend(const sigset_t * set) { int ret = -1; sigset_t oset; @@ -68,5 +68,15 @@ _libc_sigsuspend(const sigset_t * set) return (ret); } -__weak_reference(_libc_sigsuspend, sigsuspend); +int +sigsuspend(const sigset_t * set) +{ + int ret; + + _thread_enter_cancellation_point(); + ret = _sigsuspend(set); + _thread_leave_cancellation_point(); + + return ret; +} #endif diff --git a/lib/libpthread/thread/thr_sigwait.c b/lib/libpthread/thread/thr_sigwait.c index faa227e..a509687 100644 --- a/lib/libpthread/thread/thr_sigwait.c +++ b/lib/libpthread/thread/thr_sigwait.c @@ -143,6 +143,7 @@ sigwait(const sigset_t * set, int *sig) } _thread_leave_cancellation_point(); + /* Return the completion status: */ return (ret); } diff --git a/lib/libpthread/thread/thr_sleep.c b/lib/libpthread/thread/thr_sleep.c new file mode 100644 index 0000000..34a5925 --- /dev/null +++ b/lib/libpthread/thread/thr_sleep.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2000 Jason Evans <jasone@canonware.com>. + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD$ + */ + +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +unsigned int +sleep(unsigned int seconds) +{ + unsigned int ret; + + _thread_enter_cancellation_point(); + ret = __sleep(seconds); + _thread_leave_cancellation_point(); + + return ret; +} +#endif diff --git a/lib/libpthread/thread/thr_spinlock.c b/lib/libpthread/thread/thr_spinlock.c index 4e94ffc..e797f90 100644 --- a/lib/libpthread/thread/thr_spinlock.c +++ b/lib/libpthread/thread/thr_spinlock.c @@ -90,7 +90,7 @@ _spinlock_debug(spinlock_t *lck, char *fname, int lineno) char str[256]; snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, _thread_run, lck, fname, lineno, lck->fname, lck->lineno); _thread_sys_write(2,str,strlen(str)); - sleep(1); + __sleep(1); cnt = 0; } diff --git a/lib/libpthread/thread/thr_system.c b/lib/libpthread/thread/thr_system.c new file mode 100644 index 0000000..9265975 --- /dev/null +++ b/lib/libpthread/thread/thr_system.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2000 Jason Evans <jasone@canonware.com>. + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD$ + */ + +#include <stdlib.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +int +system(const char *string) +{ + int ret; + + _thread_enter_cancellation_point(); + ret = __system(string); + _thread_leave_cancellation_point(); + + return ret; +} +#endif diff --git a/lib/libpthread/thread/thr_tcdrain.c b/lib/libpthread/thread/thr_tcdrain.c new file mode 100644 index 0000000..d040599 --- /dev/null +++ b/lib/libpthread/thread/thr_tcdrain.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2000 Jason Evans <jasone@canonware.com>. + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD$ + */ + +#include <termios.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +int +tcdrain(int fd) +{ + int ret; + + _thread_enter_cancellation_point(); + ret = __tcdrain(fd); + _thread_leave_cancellation_point(); + + return ret; +} +#endif diff --git a/lib/libpthread/thread/thr_wait.c b/lib/libpthread/thread/thr_wait.c new file mode 100644 index 0000000..abc19cc --- /dev/null +++ b/lib/libpthread/thread/thr_wait.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2000 Jason Evans <jasone@canonware.com>. + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD$ + */ + +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +pid_t +wait(int *istat) +{ + pid_t ret; + + _thread_enter_cancellation_point(); + ret = __wait(istat); + _thread_leave_cancellation_point(); + + return ret; +} +#endif diff --git a/lib/libpthread/thread/thr_wait4.c b/lib/libpthread/thread/thr_wait4.c index 4c3f1de..90eb0ab 100644 --- a/lib/libpthread/thread/thr_wait4.c +++ b/lib/libpthread/thread/thr_wait4.c @@ -38,11 +38,10 @@ #include "pthread_private.h" pid_t -_libc_wait4(pid_t pid, int *istat, int options, struct rusage * rusage) +_wait4(pid_t pid, int *istat, int options, struct rusage * rusage) { pid_t ret; - _thread_enter_cancellation_point(); _thread_kern_sig_defer(); /* Perform a non-blocking wait4 syscall: */ @@ -62,10 +61,9 @@ _libc_wait4(pid_t pid, int *istat, int options, struct rusage * rusage) } _thread_kern_sig_undefer(); - _thread_leave_cancellation_point(); return (ret); } -__weak_reference(_libc_wait4, wait4); +__weak_reference(_wait4, wait4); #endif diff --git a/lib/libpthread/thread/thr_waitpid.c b/lib/libpthread/thread/thr_waitpid.c new file mode 100644 index 0000000..a847295 --- /dev/null +++ b/lib/libpthread/thread/thr_waitpid.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2000 Jason Evans <jasone@canonware.com>. + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD$ + */ + +#include <sys/types.h> +#include <sys/wait.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +pid_t +waitpid(pid_t wpid, int *status, int options) +{ + pid_t ret; + + _thread_enter_cancellation_point(); + ret = __waitpid(wpid, status, options); + _thread_leave_cancellation_point(); + + return ret; +} +#endif diff --git a/lib/libpthread/thread/thr_write.c b/lib/libpthread/thread/thr_write.c index f25c606..6408a64 100644 --- a/lib/libpthread/thread/thr_write.c +++ b/lib/libpthread/thread/thr_write.c @@ -42,7 +42,7 @@ #include "pthread_private.h" ssize_t -_libc_write(int fd, const void *buf, size_t nbytes) +_write(int fd, const void *buf, size_t nbytes) { int blocking; int type; @@ -50,12 +50,9 @@ _libc_write(int fd, const void *buf, size_t nbytes) ssize_t num = 0; ssize_t ret; - _thread_enter_cancellation_point(); /* POSIX says to do just this: */ - if (nbytes == 0) { - _thread_leave_cancellation_point(); + if (nbytes == 0) return (0); - } /* Lock the file descriptor for write: */ if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { @@ -67,7 +64,6 @@ _libc_write(int fd, const void *buf, size_t nbytes) /* File is not open for write: */ errno = EBADF; _FD_UNLOCK(fd, FD_WRITE); - _thread_leave_cancellation_point(); return (-1); } @@ -133,9 +129,18 @@ _libc_write(int fd, const void *buf, size_t nbytes) } _FD_UNLOCK(fd, FD_RDWR); } - _thread_leave_cancellation_point(); return (ret); } -__weak_reference(_libc_write, write); +ssize_t +write(int fd, const void *buf, size_t nbytes) +{ + ssize_t ret; + + _thread_enter_cancellation_point(); + ret = _write(fd, buf, nbytes); + _thread_leave_cancellation_point(); + + return ret; +} #endif diff --git a/lib/libpthread/thread/thr_writev.c b/lib/libpthread/thread/thr_writev.c index 74da521..7c5fffe 100644 --- a/lib/libpthread/thread/thr_writev.c +++ b/lib/libpthread/thread/thr_writev.c @@ -44,7 +44,7 @@ #include "pthread_private.h" ssize_t -_libc_writev(int fd, const struct iovec * iov, int iovcnt) +_writev(int fd, const struct iovec * iov, int iovcnt) { int blocking; int idx = 0; @@ -201,5 +201,5 @@ _libc_writev(int fd, const struct iovec * iov, int iovcnt) return (ret); } -__weak_reference(_libc_writev, writev); +__weak_reference(_writev, writev); #endif |