diff options
author | David Leonard <d@cvs.openbsd.org> | 1999-11-25 07:01:48 +0000 |
---|---|---|
committer | David Leonard <d@cvs.openbsd.org> | 1999-11-25 07:01:48 +0000 |
commit | 0fe78c3128864d128b2b10153b8d533ff8c00375 (patch) | |
tree | 5229c3d97eed15f4d71927a5f454180aef2632f6 /lib/libc_r/uthread/uthread_fd.c | |
parent | ed00fa742a6455d22e3b56cf846dc5acd7a51fd7 (diff) |
sync with FreeBSD
Diffstat (limited to 'lib/libc_r/uthread/uthread_fd.c')
-rw-r--r-- | lib/libc_r/uthread/uthread_fd.c | 86 |
1 files changed, 63 insertions, 23 deletions
diff --git a/lib/libc_r/uthread/uthread_fd.c b/lib/libc_r/uthread/uthread_fd.c index 0b51f75b737..39303fc0820 100644 --- a/lib/libc_r/uthread/uthread_fd.c +++ b/lib/libc_r/uthread/uthread_fd.c @@ -1,3 +1,4 @@ +/* $OpenBSD: uthread_fd.c,v 1.6 1999/11/25 07:01:34 d Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -20,7 +21,7 @@ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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) @@ -29,8 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: uthread_fd.c,v 1.10 1999/03/23 05:07:55 jb Exp $ - * $OpenBSD: uthread_fd.c,v 1.5 1999/05/26 00:18:23 d Exp $ + * $FreeBSD: uthread_fd.c,v 1.13 1999/08/28 00:03:31 peter Exp $ * */ #include <errno.h> @@ -80,28 +80,28 @@ _thread_fd_table_init(int fd) ret = -1; } else { /* Initialise the file locks: */ - _SPINUNLOCK(&entry->lock); + _SPINLOCK_INIT(&entry->lock); entry->r_owner = NULL; entry->w_owner = NULL; entry->r_fname = NULL; entry->w_fname = NULL; - entry->r_lineno = 0;; - entry->w_lineno = 0;; - entry->r_lockcount = 0;; - entry->w_lockcount = 0;; + entry->r_lineno = 0; + entry->w_lineno = 0; + entry->r_lockcount = 0; + entry->w_lockcount = 0; /* Initialise the read/write queues: */ - _thread_queue_init(&entry->r_queue); - _thread_queue_init(&entry->w_queue); + TAILQ_INIT(&entry->r_queue); + TAILQ_INIT(&entry->w_queue); /* Get the flags for the file: */ - if (fd >= 3 && (entry->flags = - _thread_sys_fcntl(fd, F_GETFL, 0)) == -1) { + if (((fd >= 3) || (_pthread_stdio_flags[fd] == -1)) && + (entry->flags = _thread_sys_fcntl(fd, F_GETFL, 0)) == -1) { ret = -1; - } + } else { /* Check if a stdio descriptor: */ - if (fd < 3) + if ((fd < 3) && (_pthread_stdio_flags[fd] != -1)) /* * Use the stdio flags read by * _pthread_init() to avoid @@ -170,6 +170,12 @@ _thread_fd_unlock(int fd, int lock_type) */ if ((ret = _thread_fd_table_init(fd)) == 0) { /* + * Defer signals to protect the scheduling queues from + * access by the signal handler: + */ + _thread_kern_sig_defer(); + + /* * Lock the file descriptor table entry to prevent * other threads for clashing with the current * thread's accesses: @@ -196,8 +202,12 @@ _thread_fd_unlock(int fd, int lock_type) * Get the next thread in the queue for a * read lock on this file descriptor: */ - else if ((_thread_fd_table[fd]->r_owner = _thread_queue_deq(&_thread_fd_table[fd]->r_queue)) == NULL) { + else if ((_thread_fd_table[fd]->r_owner = TAILQ_FIRST(&_thread_fd_table[fd]->r_queue)) == NULL) { } else { + /* Remove this thread from the queue: */ + TAILQ_REMOVE(&_thread_fd_table[fd]->r_queue, + _thread_fd_table[fd]->r_owner, qe); + /* * Set the state of the new owner of * the thread to running: @@ -234,8 +244,12 @@ _thread_fd_unlock(int fd, int lock_type) * Get the next thread in the queue for a * write lock on this file descriptor: */ - else if ((_thread_fd_table[fd]->w_owner = _thread_queue_deq(&_thread_fd_table[fd]->w_queue)) == NULL) { + else if ((_thread_fd_table[fd]->w_owner = TAILQ_FIRST(&_thread_fd_table[fd]->w_queue)) == NULL) { } else { + /* Remove this thread from the queue: */ + TAILQ_REMOVE(&_thread_fd_table[fd]->w_queue, + _thread_fd_table[fd]->w_owner, qe); + /* * Set the state of the new owner of * the thread to running: @@ -255,6 +269,12 @@ _thread_fd_unlock(int fd, int lock_type) /* Unlock the file descriptor table entry: */ _SPINUNLOCK(&_thread_fd_table[fd]->lock); + + /* + * Undefer and handle pending signals, yielding if + * necessary: + */ + _thread_kern_sig_undefer(); } /* Nothing to return. */ @@ -296,7 +316,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) * queue of threads waiting for a * read lock on this file descriptor: */ - _thread_queue_enq(&_thread_fd_table[fd]->r_queue, _thread_run); + TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->r_queue, _thread_run, qe); /* * Save the file descriptor details @@ -369,7 +389,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) * write lock on this file * descriptor: */ - _thread_queue_enq(&_thread_fd_table[fd]->w_queue, _thread_run); + TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->w_queue, _thread_run, qe); /* * Save the file descriptor details @@ -431,7 +451,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) } void -_thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) +_thread_fd_unlock_debug(int fd, int lock_type, const char *fname, int lineno) { int ret; @@ -441,6 +461,12 @@ _thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) */ if ((ret = _thread_fd_table_init(fd)) == 0) { /* + * Defer signals to protect the scheduling queues from + * access by the signal handler: + */ + _thread_kern_sig_defer(); + + /* * Lock the file descriptor table entry to prevent * other threads for clashing with the current * thread's accesses: @@ -467,8 +493,12 @@ _thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) * Get the next thread in the queue for a * read lock on this file descriptor: */ - else if ((_thread_fd_table[fd]->r_owner = _thread_queue_deq(&_thread_fd_table[fd]->r_queue)) == NULL) { + else if ((_thread_fd_table[fd]->r_owner = TAILQ_FIRST(&_thread_fd_table[fd]->r_queue)) == NULL) { } else { + /* Remove this thread from the queue: */ + TAILQ_REMOVE(&_thread_fd_table[fd]->r_queue, + _thread_fd_table[fd]->r_owner, qe); + /* * Set the state of the new owner of * the thread to running: @@ -505,8 +535,12 @@ _thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) * Get the next thread in the queue for a * write lock on this file descriptor: */ - else if ((_thread_fd_table[fd]->w_owner = _thread_queue_deq(&_thread_fd_table[fd]->w_queue)) == NULL) { + else if ((_thread_fd_table[fd]->w_owner = TAILQ_FIRST(&_thread_fd_table[fd]->w_queue)) == NULL) { } else { + /* Remove this thread from the queue: */ + TAILQ_REMOVE(&_thread_fd_table[fd]->w_queue, + _thread_fd_table[fd]->w_owner, qe); + /* * Set the state of the new owner of * the thread to running: @@ -526,6 +560,12 @@ _thread_fd_unlock_debug(int fd, int lock_type, char *fname, int lineno) /* Unlock the file descriptor table entry: */ _SPINUNLOCK(&_thread_fd_table[fd]->lock); + + /* + * Undefer and handle pending signals, yielding if + * necessary. + */ + _thread_kern_sig_undefer(); } /* Nothing to return. */ @@ -568,7 +608,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * queue of threads waiting for a * read lock on this file descriptor: */ - _thread_queue_enq(&_thread_fd_table[fd]->r_queue, _thread_run); + TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->r_queue, _thread_run, qe); /* * Save the file descriptor details @@ -650,7 +690,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * write lock on this file * descriptor: */ - _thread_queue_enq(&_thread_fd_table[fd]->w_queue, _thread_run); + TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->w_queue, _thread_run, qe); /* * Save the file descriptor details |