diff options
author | jb <jb@FreeBSD.org> | 1998-06-09 23:21:05 +0000 |
---|---|---|
committer | jb <jb@FreeBSD.org> | 1998-06-09 23:21:05 +0000 |
commit | 765df5f4d29065eac50b4bfab3407a7da8a90323 (patch) | |
tree | e14930dc53674181c346bbe0f43647669e330569 /lib/libc_r | |
parent | 5ed1d7e9485fa8756d1be3fdf6cfa5125ac45657 (diff) | |
download | FreeBSD-src-765df5f4d29065eac50b4bfab3407a7da8a90323.zip FreeBSD-src-765df5f4d29065eac50b4bfab3407a7da8a90323.tar.gz |
Implement compile time debug support instead of tracking file name and
line number every time a file descriptor is locked.
This looks like a big change but it isn't. It should reduce the size
of libc_r and make it run slightly faster.
Diffstat (limited to 'lib/libc_r')
36 files changed, 154 insertions, 147 deletions
diff --git a/lib/libc_r/uthread/uthread_accept.c b/lib/libc_r/uthread/uthread_accept.c index 1ea1474..371da56 100644 --- a/lib/libc_r/uthread/uthread_accept.c +++ b/lib/libc_r/uthread/uthread_accept.c @@ -45,7 +45,7 @@ accept(int fd, struct sockaddr * name, int *namelen) int ret; /* Lock the file descriptor: */ - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { /* Enter a loop to wait for a connection request: */ while ((ret = _thread_sys_accept(fd, name, namelen)) < 0) { /* Check if the socket is to block: */ @@ -100,7 +100,7 @@ accept(int fd, struct sockaddr * name, int *namelen) _thread_fd_table[ret]->flags &= ~O_NONBLOCK; /* Unlock the file descriptor: */ - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } /* Return the socket file descriptor or -1 on error: */ return (ret); diff --git a/lib/libc_r/uthread/uthread_bind.c b/lib/libc_r/uthread/uthread_bind.c index adc30a1..11edfbb 100644 --- a/lib/libc_r/uthread/uthread_bind.c +++ b/lib/libc_r/uthread/uthread_bind.c @@ -41,9 +41,9 @@ bind(int fd, const struct sockaddr * name, int namelen) { int ret; - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { ret = _thread_sys_bind(fd, name, namelen); - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_close.c b/lib/libc_r/uthread/uthread_close.c index 5678e2e..7e21853 100644 --- a/lib/libc_r/uthread/uthread_close.c +++ b/lib/libc_r/uthread/uthread_close.c @@ -47,9 +47,9 @@ close(int fd) struct stat sb; /* Lock the file descriptor while the file is closed: */ - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { /* Get file descriptor status. */ - fstat(fd, &sb); + _thread_sys_fstat(fd, &sb); /* * Check if the file should be left as blocking. diff --git a/lib/libc_r/uthread/uthread_cond.c b/lib/libc_r/uthread/uthread_cond.c index cb08853..fae12eb 100644 --- a/lib/libc_r/uthread/uthread_cond.c +++ b/lib/libc_r/uthread/uthread_cond.c @@ -32,6 +32,7 @@ */ #include <stdlib.h> #include <errno.h> +#include <string.h> #ifdef _THREAD_SAFE #include <pthread.h> #include "pthread_private.h" @@ -85,7 +86,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr) _thread_queue_init(&pcond->c_queue); pcond->c_flags |= COND_FLAGS_INITED; pcond->c_type = type; - pcond->access_lock = 0; + memset(&pcond->lock,0,sizeof(pcond->lock)); *cond = pcond; } } @@ -103,7 +104,7 @@ pthread_cond_destroy(pthread_cond_t * cond) rval = EINVAL; else { /* Lock the condition variable structure: */ - _spinlock(&(*cond)->access_lock); + _SPINLOCK(&(*cond)->lock); /* * Free the memory allocated for the condition @@ -137,7 +138,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) else if (*cond != NULL || (rval = pthread_cond_init(cond,NULL)) == 0) { /* Lock the condition variable structure: */ - _spinlock(&(*cond)->access_lock); + _SPINLOCK(&(*cond)->lock); /* Process according to condition variable type: */ switch ((*cond)->c_type) { @@ -156,14 +157,14 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) _thread_run->wakeup_time.tv_sec = -1; /* Unlock the condition variable structure: */ - _atomic_unlock(&(*cond)->access_lock); + _SPINUNLOCK(&(*cond)->lock); /* Schedule the next thread: */ _thread_kern_sched_state(PS_COND_WAIT, __FILE__, __LINE__); /* Lock the condition variable structure: */ - _spinlock(&(*cond)->access_lock); + _SPINLOCK(&(*cond)->lock); /* Lock the mutex: */ rval = pthread_mutex_lock(mutex); @@ -177,7 +178,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) } /* Unlock the condition variable structure: */ - _atomic_unlock(&(*cond)->access_lock); + _SPINUNLOCK(&(*cond)->lock); } /* Return the completion status: */ @@ -201,7 +202,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, else if (*cond != NULL || (rval = pthread_cond_init(cond,NULL)) == 0) { /* Lock the condition variable structure: */ - _spinlock(&(*cond)->access_lock); + _SPINLOCK(&(*cond)->lock); /* Process according to condition variable type: */ switch ((*cond)->c_type) { @@ -230,14 +231,14 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, _thread_queue_deq(&(*cond)->c_queue); } else { /* Unlock the condition variable structure: */ - _atomic_unlock(&(*cond)->access_lock); + _SPINUNLOCK(&(*cond)->lock); /* Schedule the next thread: */ _thread_kern_sched_state(PS_COND_WAIT, __FILE__, __LINE__); /* Lock the condition variable structure: */ - _spinlock(&(*cond)->access_lock); + _SPINLOCK(&(*cond)->lock); /* Lock the mutex: */ if ((rval = pthread_mutex_lock(mutex)) != 0) { @@ -258,7 +259,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, } /* Unlock the condition variable structure: */ - _atomic_unlock(&(*cond)->access_lock); + _SPINUNLOCK(&(*cond)->lock); } /* Return the completion status: */ @@ -276,7 +277,7 @@ pthread_cond_signal(pthread_cond_t * cond) rval = EINVAL; else { /* Lock the condition variable structure: */ - _spinlock(&(*cond)->access_lock); + _SPINLOCK(&(*cond)->lock); /* Process according to condition variable type: */ switch ((*cond)->c_type) { @@ -297,7 +298,7 @@ pthread_cond_signal(pthread_cond_t * cond) } /* Unlock the condition variable structure: */ - _atomic_unlock(&(*cond)->access_lock); + _SPINUNLOCK(&(*cond)->lock); } /* Return the completion status: */ @@ -315,7 +316,7 @@ pthread_cond_broadcast(pthread_cond_t * cond) rval = EINVAL; else { /* Lock the condition variable structure: */ - _spinlock(&(*cond)->access_lock); + _SPINLOCK(&(*cond)->lock); /* Process according to condition variable type: */ switch ((*cond)->c_type) { @@ -340,7 +341,7 @@ pthread_cond_broadcast(pthread_cond_t * cond) } /* Unlock the condition variable structure: */ - _atomic_unlock(&(*cond)->access_lock); + _SPINUNLOCK(&(*cond)->lock); } /* Return the completion status: */ diff --git a/lib/libc_r/uthread/uthread_connect.c b/lib/libc_r/uthread/uthread_connect.c index 9ae03c5..d05de16 100644 --- a/lib/libc_r/uthread/uthread_connect.c +++ b/lib/libc_r/uthread/uthread_connect.c @@ -44,7 +44,7 @@ connect(int fd, const struct sockaddr * name, int namelen) struct sockaddr tmpname; int ret, tmpnamelen; - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { if ((ret = _thread_sys_connect(fd, name, namelen)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EINPROGRESS) || @@ -69,7 +69,7 @@ connect(int fd, const struct sockaddr * name, int namelen) ret = -1; } } - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_dup.c b/lib/libc_r/uthread/uthread_dup.c index 1017685..39d262d 100644 --- a/lib/libc_r/uthread/uthread_dup.c +++ b/lib/libc_r/uthread/uthread_dup.c @@ -41,7 +41,7 @@ dup(int fd) int ret; /* Lock the file descriptor: */ - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { /* Perform the 'dup' syscall: */ if ((ret = _thread_sys_dup(fd)) < 0) { } @@ -61,7 +61,7 @@ dup(int fd) } /* Unlock the file descriptor: */ - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } /* Return the completion status: */ return (ret); diff --git a/lib/libc_r/uthread/uthread_dup2.c b/lib/libc_r/uthread/uthread_dup2.c index e47230b..e9edddd 100644 --- a/lib/libc_r/uthread/uthread_dup2.c +++ b/lib/libc_r/uthread/uthread_dup2.c @@ -41,9 +41,9 @@ dup2(int fd, int newfd) int ret; /* Lock the file descriptor: */ - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { /* Lock the file descriptor: */ - if ((ret = _thread_fd_lock(newfd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(newfd, FD_RDWR, NULL)) == 0) { /* Perform the 'dup2' syscall: */ if ((ret = _thread_sys_dup2(fd, newfd)) < 0) { } @@ -63,10 +63,10 @@ dup2(int fd, int newfd) } /* Unlock the file descriptor: */ - _thread_fd_unlock(newfd, FD_RDWR); + _FD_UNLOCK(newfd, FD_RDWR); } /* Unlock the file descriptor: */ - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } /* Return the completion status: */ return (ret); diff --git a/lib/libc_r/uthread/uthread_fchmod.c b/lib/libc_r/uthread/uthread_fchmod.c index 64c0558..2156eee 100644 --- a/lib/libc_r/uthread/uthread_fchmod.c +++ b/lib/libc_r/uthread/uthread_fchmod.c @@ -41,9 +41,9 @@ fchmod(int fd, mode_t mode) { int ret; - if ((ret = _thread_fd_lock(fd, FD_WRITE, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { ret = _thread_sys_fchmod(fd, mode); - _thread_fd_unlock(fd, FD_WRITE); + _FD_UNLOCK(fd, FD_WRITE); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_fchown.c b/lib/libc_r/uthread/uthread_fchown.c index a0e5c4c..ee3ca40 100644 --- a/lib/libc_r/uthread/uthread_fchown.c +++ b/lib/libc_r/uthread/uthread_fchown.c @@ -42,9 +42,9 @@ fchown(int fd, uid_t owner, gid_t group) { int ret; - if ((ret = _thread_fd_lock(fd, FD_WRITE, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { ret = _thread_sys_fchown(fd, owner, group); - _thread_fd_unlock(fd, FD_WRITE); + _FD_UNLOCK(fd, FD_WRITE); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_fcntl.c b/lib/libc_r/uthread/uthread_fcntl.c index 9a50c1c..556bd1f 100644 --- a/lib/libc_r/uthread/uthread_fcntl.c +++ b/lib/libc_r/uthread/uthread_fcntl.c @@ -47,7 +47,7 @@ fcntl(int fd, int cmd,...) va_list ap; /* Lock the file descriptor: */ - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { /* Initialise the variable argument list: */ va_start(ap, cmd); @@ -80,8 +80,11 @@ fcntl(int fd, int cmd,...) } break; case F_SETFD: + flags = va_arg(ap, int); + ret = _thread_sys_fcntl(fd, cmd, flags); break; case F_GETFD: + ret = _thread_sys_fcntl(fd, cmd, 0); break; case F_GETFL: ret = _thread_fd_table[fd]->flags; @@ -102,7 +105,7 @@ fcntl(int fd, int cmd,...) va_end(ap); /* Unlock the file descriptor: */ - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } /* Return the completion status: */ diff --git a/lib/libc_r/uthread/uthread_file.c b/lib/libc_r/uthread/uthread_file.c index 483db47..308feda 100644 --- a/lib/libc_r/uthread/uthread_file.c +++ b/lib/libc_r/uthread/uthread_file.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_file.c,v 1.2 1998/04/11 07:47:20 jb Exp $ + * $Id: uthread_file.c,v 1.3 1998/04/29 09:58:47 jb Exp $ * * POSIX stdio FILE locking functions. These assume that the locking * is only required at FILE structure level, not at file descriptor @@ -98,7 +98,7 @@ struct static_file_lock { static int init_done = 0; /* Lock for accesses to the hash table: */ -static long hash_lock = 0; +static spinlock_t hash_lock = _SPINLOCK_INITIALIZER; /* * Find a lock structure for a FILE, return NULL if the file is @@ -189,7 +189,7 @@ _flockfile_debug(FILE * fp, char *fname, int lineno) /* Check if this is a real file: */ if (fp->_file >= 0) { /* Lock the hash table: */ - _spinlock(&hash_lock); + _SPINLOCK(&hash_lock); /* Check if the static array has not been initialised: */ if (!init_done) { @@ -209,7 +209,7 @@ _flockfile_debug(FILE * fp, char *fname, int lineno) p = do_lock(idx, fp); /* Unlock the hash table: */ - _atomic_unlock(&hash_lock); + _SPINUNLOCK(&hash_lock); /* * The file is already locked, so check if the @@ -225,7 +225,7 @@ _flockfile_debug(FILE * fp, char *fname, int lineno) p->count++; /* Unlock the hash table: */ - _atomic_unlock(&hash_lock); + _SPINUNLOCK(&hash_lock); } else { /* * The file is locked for another thread. @@ -235,7 +235,7 @@ _flockfile_debug(FILE * fp, char *fname, int lineno) TAILQ_INSERT_TAIL(&p->l_head,_thread_run,qe); /* Unlock the hash table: */ - _atomic_unlock(&hash_lock); + _SPINUNLOCK(&hash_lock); /* Wait on the FILE lock: */ _thread_kern_sched_state(PS_FILE_WAIT, fname, lineno); @@ -262,7 +262,7 @@ _ftrylockfile(FILE * fp) /* Check if this is a real file: */ if (fp->_file >= 0) { /* Lock the hash table: */ - _spinlock(&hash_lock); + _SPINLOCK(&hash_lock); /* Get a pointer to any existing lock for the file: */ if ((p = find_lock(idx, fp)) == NULL) { @@ -298,7 +298,7 @@ _ftrylockfile(FILE * fp) ret = 0; /* Unlock the hash table: */ - _atomic_unlock(&hash_lock); + _SPINUNLOCK(&hash_lock); } return (ret); @@ -314,7 +314,7 @@ _funlockfile(FILE * fp) /* Check if this is a real file: */ if (fp->_file >= 0) { /* Lock the hash table: */ - _spinlock(&hash_lock); + _SPINLOCK(&hash_lock); /* * Get a pointer to the lock for the file and check that @@ -358,7 +358,7 @@ _funlockfile(FILE * fp) } /* Unlock the hash table: */ - _atomic_unlock(&hash_lock); + _SPINUNLOCK(&hash_lock); } return; } diff --git a/lib/libc_r/uthread/uthread_flock.c b/lib/libc_r/uthread/uthread_flock.c index 85dd2d9..de5b61d 100644 --- a/lib/libc_r/uthread/uthread_flock.c +++ b/lib/libc_r/uthread/uthread_flock.c @@ -40,9 +40,9 @@ flock(int fd, int operation) { int ret; - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { ret = _thread_sys_flock(fd, operation); - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_fstat.c b/lib/libc_r/uthread/uthread_fstat.c index 8c875ea..20dac73 100644 --- a/lib/libc_r/uthread/uthread_fstat.c +++ b/lib/libc_r/uthread/uthread_fstat.c @@ -46,11 +46,11 @@ fstat(int fd, struct stat * buf) int ret; /* Lock the file descriptor for read: */ - if ((ret = _thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { /* Get the file status: */ ret = _thread_sys_fstat(fd, buf); /* Unlock the file descriptor: */ - _thread_fd_unlock(fd, FD_READ); + _FD_UNLOCK(fd, FD_READ); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_fstatfs.c b/lib/libc_r/uthread/uthread_fstatfs.c index 1216c82..f236fef 100644 --- a/lib/libc_r/uthread/uthread_fstatfs.c +++ b/lib/libc_r/uthread/uthread_fstatfs.c @@ -46,11 +46,11 @@ fstatfs(int fd, struct statfs * buf) int ret; /* Lock the file descriptor for read: */ - if ((ret = _thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { /* Get the file system status: */ ret = _thread_sys_fstatfs(fd, buf); /* Unlock the file descriptor: */ - _thread_fd_unlock(fd, FD_READ); + _FD_UNLOCK(fd, FD_READ); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_fsync.c b/lib/libc_r/uthread/uthread_fsync.c index 5658c73..9141d47 100644 --- a/lib/libc_r/uthread/uthread_fsync.c +++ b/lib/libc_r/uthread/uthread_fsync.c @@ -40,9 +40,9 @@ fsync(int fd) { int ret; - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { ret = _thread_sys_fsync(fd); - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_getdirentries.c b/lib/libc_r/uthread/uthread_getdirentries.c index a1fd5b4..44e7520 100644 --- a/lib/libc_r/uthread/uthread_getdirentries.c +++ b/lib/libc_r/uthread/uthread_getdirentries.c @@ -41,9 +41,9 @@ getdirentries(int fd, char *buf, int nbytes, long *basep) { int ret; - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { ret = _thread_sys_getdirentries(fd, buf, nbytes, basep); - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_getpeername.c b/lib/libc_r/uthread/uthread_getpeername.c index 3052bea2..7b2cd03 100644 --- a/lib/libc_r/uthread/uthread_getpeername.c +++ b/lib/libc_r/uthread/uthread_getpeername.c @@ -41,9 +41,9 @@ getpeername(int fd, struct sockaddr * peer, int *paddrlen) { int ret; - if ((ret = _thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { ret = _thread_sys_getpeername(fd, peer, paddrlen); - _thread_fd_unlock(fd, FD_READ); + _FD_UNLOCK(fd, FD_READ); } return ret; } diff --git a/lib/libc_r/uthread/uthread_getsockname.c b/lib/libc_r/uthread/uthread_getsockname.c index df73fed..0b40fc5 100644 --- a/lib/libc_r/uthread/uthread_getsockname.c +++ b/lib/libc_r/uthread/uthread_getsockname.c @@ -41,9 +41,9 @@ getsockname(int s, struct sockaddr * name, int *namelen) { int ret; - if ((ret = _thread_fd_lock(s, FD_READ, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(s, FD_READ, NULL)) == 0) { ret = _thread_sys_getsockname(s, name, namelen); - _thread_fd_unlock(s, FD_READ); + _FD_UNLOCK(s, FD_READ); } return ret; } diff --git a/lib/libc_r/uthread/uthread_getsockopt.c b/lib/libc_r/uthread/uthread_getsockopt.c index 49afa15..fe3478b 100644 --- a/lib/libc_r/uthread/uthread_getsockopt.c +++ b/lib/libc_r/uthread/uthread_getsockopt.c @@ -41,9 +41,9 @@ getsockopt(int fd, int level, int optname, void *optval, int *optlen) { int ret; - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { ret = _thread_sys_getsockopt(fd, level, optname, optval, optlen); - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } return ret; } diff --git a/lib/libc_r/uthread/uthread_info.c b/lib/libc_r/uthread/uthread_info.c index c2c3426..16562ac 100644 --- a/lib/libc_r/uthread/uthread_info.c +++ b/lib/libc_r/uthread/uthread_info.c @@ -154,7 +154,7 @@ _thread_dump_info(void) } /* Output a header for file descriptors: */ - strcpy(s, "\n\n=============\nFILE DESCRIPTOR TABLE\n\n"); + snprintf(s, sizeof(s), "\n\n=============\nFILE DESCRIPTOR TABLE (table size %d)\n\n",_thread_dtablesize); _thread_sys_write(fd, s, strlen(s)); /* Enter a loop to report file descriptor lock usage: */ diff --git a/lib/libc_r/uthread/uthread_ioctl.c b/lib/libc_r/uthread/uthread_ioctl.c index 5a9b30c..79f075a 100644 --- a/lib/libc_r/uthread/uthread_ioctl.c +++ b/lib/libc_r/uthread/uthread_ioctl.c @@ -45,7 +45,7 @@ ioctl(int fd, unsigned long request,...) va_list ap; /* Lock the file descriptor: */ - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { /* Initialise the variable argument list: */ va_start(ap, request); @@ -69,7 +69,7 @@ ioctl(int fd, unsigned long request,...) va_end(ap); /* Unlock the file descriptor: */ - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } /* Return the completion status: */ diff --git a/lib/libc_r/uthread/uthread_listen.c b/lib/libc_r/uthread/uthread_listen.c index 7c6f81d..58d96dc 100644 --- a/lib/libc_r/uthread/uthread_listen.c +++ b/lib/libc_r/uthread/uthread_listen.c @@ -41,9 +41,9 @@ listen(int fd, int backlog) { int ret; - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { ret = _thread_sys_listen(fd, backlog); - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_mutex.c b/lib/libc_r/uthread/uthread_mutex.c index fb737cf..95c2083 100644 --- a/lib/libc_r/uthread/uthread_mutex.c +++ b/lib/libc_r/uthread/uthread_mutex.c @@ -32,6 +32,7 @@ */ #include <stdlib.h> #include <errno.h> +#include <string.h> #ifdef _THREAD_SAFE #include <pthread.h> #include "pthread_private.h" @@ -94,7 +95,8 @@ pthread_mutex_init(pthread_mutex_t * mutex, pmutex->m_flags |= MUTEX_FLAGS_INITED; pmutex->m_owner = NULL; pmutex->m_type = type; - pmutex->access_lock = 0; + memset(&pmutex->lock, 0, + sizeof(pmutex->lock)); *mutex = pmutex; } else { free(pmutex); @@ -116,7 +118,7 @@ pthread_mutex_destroy(pthread_mutex_t * mutex) ret = EINVAL; else { /* Lock the mutex structure: */ - _spinlock(&(*mutex)->access_lock); + _SPINLOCK(&(*mutex)->lock); /* * Free the memory allocated for the mutex @@ -150,7 +152,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex) else if (*mutex != NULL || (ret = pthread_mutex_init(mutex,NULL)) == 0) { /* Lock the mutex structure: */ - _spinlock(&(*mutex)->access_lock); + _SPINLOCK(&(*mutex)->lock); /* Process according to mutex type: */ switch ((*mutex)->m_type) { @@ -195,7 +197,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex) } /* Unlock the mutex structure: */ - _atomic_unlock(&(*mutex)->access_lock); + _SPINUNLOCK(&(*mutex)->lock); } /* Return the completion status: */ @@ -217,7 +219,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex) else if (*mutex != NULL || (ret = pthread_mutex_init(mutex,NULL)) == 0) { /* Lock the mutex structure: */ - _spinlock(&(*mutex)->access_lock); + _SPINLOCK(&(*mutex)->lock); /* Process according to mutex type: */ switch ((*mutex)->m_type) { @@ -240,13 +242,13 @@ pthread_mutex_lock(pthread_mutex_t * mutex) _thread_queue_enq(&(*mutex)->m_queue, _thread_run); /* Unlock the mutex structure: */ - _atomic_unlock(&(*mutex)->access_lock); + _SPINUNLOCK(&(*mutex)->lock); /* Block signals: */ _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__); /* Lock the mutex again: */ - _spinlock(&(*mutex)->access_lock); + _SPINLOCK(&(*mutex)->lock); } } break; @@ -273,13 +275,13 @@ pthread_mutex_lock(pthread_mutex_t * mutex) _thread_queue_enq(&(*mutex)->m_queue, _thread_run); /* Unlock the mutex structure: */ - _atomic_unlock(&(*mutex)->access_lock); + _SPINUNLOCK(&(*mutex)->lock); /* Block signals: */ _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__); /* Lock the mutex again: */ - _spinlock(&(*mutex)->access_lock); + _SPINLOCK(&(*mutex)->lock); } } @@ -295,7 +297,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex) } /* Unlock the mutex structure: */ - _atomic_unlock(&(*mutex)->access_lock); + _SPINUNLOCK(&(*mutex)->lock); } /* Return the completion status: */ @@ -311,7 +313,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex) ret = EINVAL; } else { /* Lock the mutex structure: */ - _spinlock(&(*mutex)->access_lock); + _SPINLOCK(&(*mutex)->lock); /* Process according to mutex type: */ switch ((*mutex)->m_type) { @@ -362,7 +364,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex) } /* Unlock the mutex structure: */ - _atomic_unlock(&(*mutex)->access_lock); + _SPINUNLOCK(&(*mutex)->lock); } /* Return the completion status: */ diff --git a/lib/libc_r/uthread/uthread_read.c b/lib/libc_r/uthread/uthread_read.c index 76df2cf..358a620 100644 --- a/lib/libc_r/uthread/uthread_read.c +++ b/lib/libc_r/uthread/uthread_read.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_read.c,v 1.3 1997/04/01 22:44:15 jb Exp $ + * $Id: uthread_read.c,v 1.4 1998/04/29 09:59:10 jb Exp $ * */ #include <sys/types.h> @@ -46,9 +46,12 @@ read(int fd, void *buf, size_t nbytes) { int ret; + /* POSIX says to do just this: */ + if (nbytes == 0) + return (0); + /* Lock the file descriptor for read: */ - if ((ret = _thread_fd_lock(fd, FD_READ, NULL, - __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { /* Perform a non-blocking read syscall: */ while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) { if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && @@ -75,7 +78,7 @@ read(int fd, void *buf, size_t nbytes) break; } } - _thread_fd_unlock(fd, FD_READ); + _FD_UNLOCK(fd, FD_READ); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_readv.c b/lib/libc_r/uthread/uthread_readv.c index 10d1a43..0a19290b 100644 --- a/lib/libc_r/uthread/uthread_readv.c +++ b/lib/libc_r/uthread/uthread_readv.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_readv.c,v 1.3 1997/04/01 22:44:16 jb Exp $ + * $Id: uthread_readv.c,v 1.4 1998/04/29 09:59:11 jb Exp $ * */ #include <sys/types.h> @@ -47,8 +47,7 @@ readv(int fd, const struct iovec * iov, int iovcnt) int ret; /* Lock the file descriptor for read: */ - if ((ret = _thread_fd_lock(fd, FD_READ, NULL, - __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { /* Perform a non-blocking readv syscall: */ while ((ret = _thread_sys_readv(fd, iov, iovcnt)) < 0) { if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && @@ -75,7 +74,7 @@ readv(int fd, const struct iovec * iov, int iovcnt) break; } } - _thread_fd_unlock(fd, FD_READ); + _FD_UNLOCK(fd, FD_READ); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_recvfrom.c b/lib/libc_r/uthread/uthread_recvfrom.c index 8d5d9db..e8a3741 100644 --- a/lib/libc_r/uthread/uthread_recvfrom.c +++ b/lib/libc_r/uthread/uthread_recvfrom.c @@ -43,7 +43,7 @@ recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from, int * { int ret; - if ((ret = _thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { while ((ret = _thread_sys_recvfrom(fd, buf, len, flags, from, from_len)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { _thread_run->data.fd.fd = fd; @@ -65,7 +65,7 @@ recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from, int * break; } } - _thread_fd_unlock(fd, FD_READ); + _FD_UNLOCK(fd, FD_READ); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_recvmsg.c b/lib/libc_r/uthread/uthread_recvmsg.c index a0ae08a..44a4a65 100644 --- a/lib/libc_r/uthread/uthread_recvmsg.c +++ b/lib/libc_r/uthread/uthread_recvmsg.c @@ -43,7 +43,7 @@ recvmsg(int fd, struct msghdr *msg, int flags) { int ret; - if ((ret = _thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { while ((ret = _thread_sys_recvmsg(fd, msg, flags)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { _thread_run->data.fd.fd = fd; @@ -65,7 +65,7 @@ recvmsg(int fd, struct msghdr *msg, int flags) break; } } - _thread_fd_unlock(fd, FD_READ); + _FD_UNLOCK(fd, FD_READ); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_select.c b/lib/libc_r/uthread/uthread_select.c index 96df9c1..0211883 100644 --- a/lib/libc_r/uthread/uthread_select.c +++ b/lib/libc_r/uthread/uthread_select.c @@ -73,13 +73,13 @@ select(int numfds, fd_set * readfds, fd_set * writefds, for (i = 0; i < numfds; i++) { if ((readfds && (FD_ISSET(i, readfds))) || (exceptfds && FD_ISSET(i, exceptfds))) { if (writefds && FD_ISSET(i, writefds)) { - if ((ret = _thread_fd_lock(i, FD_RDWR, NULL, __FILE__, __LINE__)) != 0) { + if ((ret = _FD_LOCK(i, FD_RDWR, NULL)) != 0) { got_all_locks = 0; break; } FD_SET(i, &rdwr_locks); } else { - if ((ret = _thread_fd_lock(i, FD_READ, NULL, __FILE__, __LINE__)) != 0) { + if ((ret = _FD_LOCK(i, FD_READ, NULL)) != 0) { got_all_locks = 0; break; } @@ -87,7 +87,7 @@ select(int numfds, fd_set * readfds, fd_set * writefds, } } else { if (writefds && FD_ISSET(i, writefds)) { - if ((ret = _thread_fd_lock(i, FD_WRITE, NULL, __FILE__, __LINE__)) != 0) { + if ((ret = _FD_LOCK(i, FD_WRITE, NULL)) != 0) { got_all_locks = 0; break; } @@ -137,13 +137,13 @@ select(int numfds, fd_set * readfds, fd_set * writefds, /* clean up the locks */ for (i = 0; i < numfds; i++) if (FD_ISSET(i, &read_locks)) - _thread_fd_unlock(i, FD_READ); + _FD_UNLOCK(i, FD_READ); for (i = 0; i < numfds; i++) if (FD_ISSET(i, &rdwr_locks)) - _thread_fd_unlock(i, FD_RDWR); + _FD_UNLOCK(i, FD_RDWR); for (i = 0; i < numfds; i++) if (FD_ISSET(i, &write_locks)) - _thread_fd_unlock(i, FD_WRITE); + _FD_UNLOCK(i, FD_WRITE); if (ret > 0) { if (readfds != NULL) { diff --git a/lib/libc_r/uthread/uthread_sendmsg.c b/lib/libc_r/uthread/uthread_sendmsg.c index 82c23e7..9d97c12 100644 --- a/lib/libc_r/uthread/uthread_sendmsg.c +++ b/lib/libc_r/uthread/uthread_sendmsg.c @@ -43,7 +43,7 @@ sendmsg(int fd, const struct msghdr *msg, int flags) { int ret; - if ((ret = _thread_fd_lock(fd, FD_WRITE, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { while ((ret = _thread_sys_sendmsg(fd, msg, flags)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { _thread_run->data.fd.fd = fd; @@ -64,7 +64,7 @@ sendmsg(int fd, const struct msghdr *msg, int flags) break; } } - _thread_fd_unlock(fd, FD_WRITE); + _FD_UNLOCK(fd, FD_WRITE); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_sendto.c b/lib/libc_r/uthread/uthread_sendto.c index afac661..7dedaaa 100644 --- a/lib/libc_r/uthread/uthread_sendto.c +++ b/lib/libc_r/uthread/uthread_sendto.c @@ -43,7 +43,7 @@ sendto(int fd, const void *msg, size_t len, int flags, const struct sockaddr * t { int ret; - if ((ret = _thread_fd_lock(fd, FD_WRITE, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { while ((ret = _thread_sys_sendto(fd, msg, len, flags, to, to_len)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { _thread_run->data.fd.fd = fd; @@ -64,7 +64,7 @@ sendto(int fd, const void *msg, size_t len, int flags, const struct sockaddr * t break; } } - _thread_fd_unlock(fd, FD_WRITE); + _FD_UNLOCK(fd, FD_WRITE); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_setsockopt.c b/lib/libc_r/uthread/uthread_setsockopt.c index 0fed796..a14b338 100644 --- a/lib/libc_r/uthread/uthread_setsockopt.c +++ b/lib/libc_r/uthread/uthread_setsockopt.c @@ -41,9 +41,9 @@ setsockopt(int fd, int level, int optname, const void *optval, int optlen) { int ret; - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { ret = _thread_sys_setsockopt(fd, level, optname, optval, optlen); - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } return ret; } diff --git a/lib/libc_r/uthread/uthread_shutdown.c b/lib/libc_r/uthread/uthread_shutdown.c index b698c67..855be90 100644 --- a/lib/libc_r/uthread/uthread_shutdown.c +++ b/lib/libc_r/uthread/uthread_shutdown.c @@ -44,21 +44,21 @@ shutdown(int fd, int how) switch (how) { case 0: - if ((ret = _thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { ret = _thread_sys_shutdown(fd, how); - _thread_fd_unlock(fd, FD_READ); + _FD_UNLOCK(fd, FD_READ); } break; case 1: - if ((ret = _thread_fd_lock(fd, FD_WRITE, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { ret = _thread_sys_shutdown(fd, how); - _thread_fd_unlock(fd, FD_WRITE); + _FD_UNLOCK(fd, FD_WRITE); } break; case 2: - if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { ret = _thread_sys_shutdown(fd, how); - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } break; default: diff --git a/lib/libc_r/uthread/uthread_sig.c b/lib/libc_r/uthread/uthread_sig.c index c0fbfd1..43ef9e6 100644 --- a/lib/libc_r/uthread/uthread_sig.c +++ b/lib/libc_r/uthread/uthread_sig.c @@ -39,17 +39,17 @@ #include "pthread_private.h" /* Static variables: */ -static int volatile yield_on_unlock_dead = 0; -static int volatile yield_on_unlock_thread = 0; -static long volatile thread_dead_lock = 0; -static long volatile thread_link_list_lock = 0; +static int volatile yield_on_unlock_dead = 0; +static int volatile yield_on_unlock_thread = 0; +static spinlock_t thread_dead_lock = _SPINLOCK_INITIALIZER; +static spinlock_t thread_link_list_lock = _SPINLOCK_INITIALIZER; /* Lock the thread list: */ void _lock_thread_list() { /* Lock the thread list: */ - _spinlock(&thread_link_list_lock); + _SPINLOCK(&thread_link_list_lock); } /* Lock the dead thread list: */ @@ -57,7 +57,7 @@ void _lock_dead_thread_list() { /* Lock the dead thread list: */ - _spinlock(&thread_dead_lock); + _SPINLOCK(&thread_dead_lock); } /* Lock the thread list: */ @@ -65,7 +65,7 @@ void _unlock_thread_list() { /* Unlock the thread list: */ - _atomic_unlock(&thread_link_list_lock); + _SPINUNLOCK(&thread_link_list_lock); /* * Check if a scheduler interrupt occurred while the thread @@ -85,7 +85,7 @@ void _unlock_dead_thread_list() { /* Unlock the dead thread list: */ - _atomic_unlock(&thread_dead_lock); + _SPINUNLOCK(&thread_dead_lock); /* * Check if a scheduler interrupt occurred while the dead @@ -137,7 +137,7 @@ _thread_sig_handler(int sig, int code, struct sigcontext * scp) * unfortunate time which one of the threads is * modifying the thread list: */ - if (thread_link_list_lock) + if (thread_link_list_lock.access_lock) /* * Set a flag so that the thread that has * the lock yields when it unlocks the @@ -149,7 +149,7 @@ _thread_sig_handler(int sig, int code, struct sigcontext * scp) * unfortunate time which one of the threads is * modifying the dead thread list: */ - if (thread_dead_lock) + if (thread_dead_lock.access_lock) /* * Set a flag so that the thread that has * the lock yields when it unlocks the diff --git a/lib/libc_r/uthread/uthread_spec.c b/lib/libc_r/uthread/uthread_spec.c index eaad36d..745a145 100644 --- a/lib/libc_r/uthread/uthread_spec.c +++ b/lib/libc_r/uthread/uthread_spec.c @@ -46,19 +46,19 @@ pthread_key_create(pthread_key_t * key, void (*destructor) (void *)) { for ((*key) = 0; (*key) < PTHREAD_KEYS_MAX; (*key)++) { /* Lock the key table entry: */ - _spinlock(&key_table[*key].access_lock); + _SPINLOCK(&key_table[*key].lock); if (key_table[(*key)].allocated == 0) { key_table[(*key)].allocated = 1; key_table[(*key)].destructor = destructor; /* Unlock the key table entry: */ - _atomic_unlock(&key_table[*key].access_lock); + _SPINUNLOCK(&key_table[*key].lock); return (0); } /* Unlock the key table entry: */ - _atomic_unlock(&key_table[*key].access_lock); + _SPINUNLOCK(&key_table[*key].lock); } return (EAGAIN); } @@ -70,7 +70,7 @@ pthread_key_delete(pthread_key_t key) if (key < PTHREAD_KEYS_MAX) { /* Lock the key table entry: */ - _spinlock(&key_table[key].access_lock); + _SPINLOCK(&key_table[key].lock); if (key_table[key].allocated) key_table[key].allocated = 0; @@ -78,7 +78,7 @@ pthread_key_delete(pthread_key_t key) ret = EINVAL; /* Unlock the key table entry: */ - _atomic_unlock(&key_table[key].access_lock); + _SPINUNLOCK(&key_table[key].lock); } else ret = EINVAL; return (ret); @@ -90,25 +90,33 @@ _thread_cleanupspecific(void) void *data; int key; int itr; + void (*destructor)( void *); for (itr = 0; itr < PTHREAD_DESTRUCTOR_ITERATIONS; itr++) { for (key = 0; key < PTHREAD_KEYS_MAX; key++) { if (_thread_run->specific_data_count) { /* Lock the key table entry: */ - _spinlock(&key_table[key].access_lock); + _SPINLOCK(&key_table[key].lock); + destructor = NULL; if (key_table[key].allocated) { if (_thread_run->specific_data[key]) { data = (void *) _thread_run->specific_data[key]; _thread_run->specific_data[key] = NULL; _thread_run->specific_data_count--; - if (key_table[key].destructor) - key_table[key].destructor(data); + destructor = key_table[key].destructor; } } /* Unlock the key table entry: */ - _atomic_unlock(&key_table[key].access_lock); + _SPINUNLOCK(&key_table[key].lock); + + /* + * If there is a destructore, call it + * with the key table entry unlocked: + */ + if (destructor) + destructor(data); } else { free(_thread_run->specific_data); return; @@ -140,9 +148,6 @@ pthread_setspecific(pthread_key_t key, const void *value) if ((pthread->specific_data) || (pthread->specific_data = pthread_key_allocate_data())) { if (key < PTHREAD_KEYS_MAX) { - /* Lock the key table entry: */ - _spinlock(&key_table[key].access_lock); - if (key_table[key].allocated) { if (pthread->specific_data[key] == NULL) { if (value != NULL) @@ -155,10 +160,6 @@ pthread_setspecific(pthread_key_t key, const void *value) ret = 0; } else ret = EINVAL; - - /* Unlock the key table entry: */ - _atomic_unlock(&key_table[key].access_lock); - } else ret = EINVAL; } else @@ -177,9 +178,6 @@ pthread_getspecific(pthread_key_t key) /* Check if there is specific data: */ if (pthread->specific_data != NULL && key < PTHREAD_KEYS_MAX) { - /* Lock the key table entry: */ - _spinlock(&key_table[key].access_lock); - /* Check if this key has been used before: */ if (key_table[key].allocated) { /* Return the value: */ @@ -191,9 +189,6 @@ pthread_getspecific(pthread_key_t key) */ data = NULL; } - - /* Unlock the key table entry: */ - _atomic_unlock(&key_table[key].access_lock); } else /* No specific data has been created, so just return NULL: */ data = NULL; diff --git a/lib/libc_r/uthread/uthread_write.c b/lib/libc_r/uthread/uthread_write.c index 773f615..78940e2 100644 --- a/lib/libc_r/uthread/uthread_write.c +++ b/lib/libc_r/uthread/uthread_write.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_write.c,v 1.5 1998/04/29 09:59:33 jb Exp $ + * $Id: uthread_write.c,v 1.6 1998/05/25 21:45:50 jb Exp $ * */ #include <sys/types.h> @@ -50,9 +50,12 @@ write(int fd, const void *buf, size_t nbytes) ssize_t num = 0; ssize_t ret; + /* POSIX says to do just this: */ + if (nbytes == 0) + return (0); + /* Lock the file descriptor for write: */ - if ((ret = _thread_fd_lock(fd, FD_WRITE, NULL, - __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { /* Check if file operations are to block */ blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); @@ -113,7 +116,7 @@ write(int fd, const void *buf, size_t nbytes) /* Return the number of bytes written: */ ret = num; } - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } return (ret); } diff --git a/lib/libc_r/uthread/uthread_writev.c b/lib/libc_r/uthread/uthread_writev.c index 26a6006..9810aca 100644 --- a/lib/libc_r/uthread/uthread_writev.c +++ b/lib/libc_r/uthread/uthread_writev.c @@ -29,13 +29,15 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_writev.c,v 1.6 1998/05/25 21:45:52 jb Exp $ + * $Id: uthread_writev.c,v 1.7 1998/05/27 00:44:58 jb Exp $ * */ #include <sys/types.h> #include <sys/fcntl.h> #include <sys/uio.h> #include <errno.h> +#include <stdlib.h> +#include <string.h> #include <unistd.h> #ifdef _THREAD_SAFE #include <pthread.h> @@ -68,8 +70,7 @@ writev(int fd, const struct iovec * iov, int iovcnt) memcpy(p_iov,iov,iovcnt * sizeof(struct iovec)); /* Lock the file descriptor for write: */ - if ((ret = _thread_fd_lock(fd, FD_WRITE, NULL, - __FILE__, __LINE__)) == 0) { + if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { /* Check if file operations are to block */ blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); @@ -166,7 +167,7 @@ writev(int fd, const struct iovec * iov, int iovcnt) /* Return the number of bytes written: */ ret = num; } - _thread_fd_unlock(fd, FD_RDWR); + _FD_UNLOCK(fd, FD_RDWR); } /* If memory was allocated for the array, free it: */ |