diff options
author | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2001-08-21 19:24:54 +0000 |
---|---|---|
committer | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2001-08-21 19:24:54 +0000 |
commit | 16d25a545116e8f7dfac9140d654821d417a8eba (patch) | |
tree | 3f00c8ca19e17cde8d276fc02cb5f85fa1d8e5f3 /lib/libpthread/uthread/uthread_fd.c | |
parent | 3cfb4c4b00852105397632dba44ff455c6e1cb8f (diff) |
Start syncing with FreeBSD:
o Implement _get_curthread() and _set_curthread(). Use it where possible.
o Add missing _thread_[enter|leave]_cancellation_point().
o Add a couple of not yet used vars to pthread_private.h.
o Remove return's from void functions.
This is by no means complete, but instead of doing a big commit, i'll
split it in small ones, minimizing diffs.
Diffstat (limited to 'lib/libpthread/uthread/uthread_fd.c')
-rw-r--r-- | lib/libpthread/uthread/uthread_fd.c | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/lib/libpthread/uthread/uthread_fd.c b/lib/libpthread/uthread/uthread_fd.c index 39303fc0820..b49a3cda8fb 100644 --- a/lib/libpthread/uthread/uthread_fd.c +++ b/lib/libpthread/uthread/uthread_fd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_fd.c,v 1.6 1999/11/25 07:01:34 d Exp $ */ +/* $OpenBSD: uthread_fd.c,v 1.7 2001/08/21 19:24:53 fgsch Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -162,6 +162,7 @@ _thread_fd_table_init(int fd) void _thread_fd_unlock(int fd, int lock_type) { + struct pthread *curthread = _get_curthread(); int ret; /* @@ -183,7 +184,7 @@ _thread_fd_unlock(int fd, int lock_type) _SPINLOCK(&_thread_fd_table[fd]->lock); /* Check if the running thread owns the read lock: */ - if (_thread_fd_table[fd]->r_owner == _thread_run) { + if (_thread_fd_table[fd]->r_owner == curthread) { /* Check the file descriptor and lock types: */ if (lock_type == FD_READ || lock_type == FD_RDWR) { /* @@ -225,7 +226,7 @@ _thread_fd_unlock(int fd, int lock_type) } } /* Check if the running thread owns the write lock: */ - if (_thread_fd_table[fd]->w_owner == _thread_run) { + if (_thread_fd_table[fd]->w_owner == curthread) { /* Check the file descriptor and lock types: */ if (lock_type == FD_WRITE || lock_type == FD_RDWR) { /* @@ -284,6 +285,7 @@ _thread_fd_unlock(int fd, int lock_type) int _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) { + struct pthread *curthread = _get_curthread(); int ret; /* @@ -304,7 +306,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) * Enter a loop to wait for the file descriptor to be * locked for read for the current thread: */ - while (_thread_fd_table[fd]->r_owner != _thread_run) { + while (_thread_fd_table[fd]->r_owner != curthread) { /* * Check if the file descriptor is locked by * another thread: @@ -316,14 +318,14 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) * queue of threads waiting for a * read lock on this file descriptor: */ - TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->r_queue, _thread_run, qe); + TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->r_queue, curthread, qe); /* * Save the file descriptor details * in the thread structure for the * running thread: */ - _thread_run->data.fd.fd = fd; + curthread->data.fd.fd = fd; /* Set the timeout: */ _thread_kern_set_timeout(timeout); @@ -356,7 +358,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) * The running thread now owns the * read lock on this file descriptor: */ - _thread_fd_table[fd]->r_owner = _thread_run; + _thread_fd_table[fd]->r_owner = curthread; /* * Reset the number of read locks for @@ -376,7 +378,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) * Enter a loop to wait for the file descriptor to be * locked for write for the current thread: */ - while (_thread_fd_table[fd]->w_owner != _thread_run) { + while (_thread_fd_table[fd]->w_owner != curthread) { /* * Check if the file descriptor is locked by * another thread: @@ -389,14 +391,14 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) * write lock on this file * descriptor: */ - TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->w_queue, _thread_run, qe); + TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->w_queue, curthread, qe); /* * Save the file descriptor details * in the thread structure for the * running thread: */ - _thread_run->data.fd.fd = fd; + curthread->data.fd.fd = fd; /* Set the timeout: */ _thread_kern_set_timeout(timeout); @@ -428,7 +430,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) * write lock on this file * descriptor: */ - _thread_fd_table[fd]->w_owner = _thread_run; + _thread_fd_table[fd]->w_owner = curthread; /* * Reset the number of write locks @@ -453,6 +455,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout) void _thread_fd_unlock_debug(int fd, int lock_type, const char *fname, int lineno) { + struct pthread *curthread = _get_curthread(); int ret; /* @@ -474,7 +477,7 @@ _thread_fd_unlock_debug(int fd, int lock_type, const char *fname, int lineno) _spinlock_debug(&_thread_fd_table[fd]->lock, fname, lineno); /* Check if the running thread owns the read lock: */ - if (_thread_fd_table[fd]->r_owner == _thread_run) { + if (_thread_fd_table[fd]->r_owner == curthread) { /* Check the file descriptor and lock types: */ if (lock_type == FD_READ || lock_type == FD_RDWR) { /* @@ -516,7 +519,7 @@ _thread_fd_unlock_debug(int fd, int lock_type, const char *fname, int lineno) } } /* Check if the running thread owns the write lock: */ - if (_thread_fd_table[fd]->w_owner == _thread_run) { + if (_thread_fd_table[fd]->w_owner == curthread) { /* Check the file descriptor and lock types: */ if (lock_type == FD_WRITE || lock_type == FD_RDWR) { /* @@ -576,6 +579,7 @@ int _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, const char *fname, int lineno) { + struct pthread *curthread = _get_curthread(); int ret; /* @@ -596,7 +600,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * Enter a loop to wait for the file descriptor to be * locked for read for the current thread: */ - while (_thread_fd_table[fd]->r_owner != _thread_run) { + while (_thread_fd_table[fd]->r_owner != curthread) { /* * Check if the file descriptor is locked by * another thread: @@ -608,16 +612,16 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * queue of threads waiting for a * read lock on this file descriptor: */ - TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->r_queue, _thread_run, qe); + TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->r_queue, curthread, qe); /* * Save the file descriptor details * in the thread structure for the * running thread: */ - _thread_run->data.fd.fd = fd; - _thread_run->data.fd.branch = lineno; - _thread_run->data.fd.fname = fname; + curthread->data.fd.fd = fd; + curthread->data.fd.branch = lineno; + curthread->data.fd.fname = fname; /* Set the timeout: */ _thread_kern_set_timeout(timeout); @@ -650,7 +654,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * The running thread now owns the * read lock on this file descriptor: */ - _thread_fd_table[fd]->r_owner = _thread_run; + _thread_fd_table[fd]->r_owner = curthread; /* * Reset the number of read locks for @@ -677,7 +681,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * Enter a loop to wait for the file descriptor to be * locked for write for the current thread: */ - while (_thread_fd_table[fd]->w_owner != _thread_run) { + while (_thread_fd_table[fd]->w_owner != curthread) { /* * Check if the file descriptor is locked by * another thread: @@ -690,16 +694,16 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * write lock on this file * descriptor: */ - TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->w_queue, _thread_run, qe); + TAILQ_INSERT_TAIL(&_thread_fd_table[fd]->w_queue, curthread, qe); /* * Save the file descriptor details * in the thread structure for the * running thread: */ - _thread_run->data.fd.fd = fd; - _thread_run->data.fd.branch = lineno; - _thread_run->data.fd.fname = fname; + curthread->data.fd.fd = fd; + curthread->data.fd.branch = lineno; + curthread->data.fd.fname = fname; /* Set the timeout: */ _thread_kern_set_timeout(timeout); @@ -731,7 +735,7 @@ _thread_fd_lock_debug(int fd, int lock_type, struct timespec * timeout, * write lock on this file * descriptor: */ - _thread_fd_table[fd]->w_owner = _thread_run; + _thread_fd_table[fd]->w_owner = curthread; /* * Reset the number of write locks |