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/libkse | |
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/libkse')
-rw-r--r-- | lib/libkse/thread/thr_close.c | 4 | ||||
-rw-r--r-- | lib/libkse/thread/thr_cond.c | 29 | ||||
-rw-r--r-- | lib/libkse/thread/thr_fcntl.c | 7 | ||||
-rw-r--r-- | lib/libkse/thread/thr_fsync.c | 4 | ||||
-rw-r--r-- | lib/libkse/thread/thr_info.c | 2 | ||||
-rw-r--r-- | lib/libkse/thread/thr_mutex.c | 26 | ||||
-rw-r--r-- | lib/libkse/thread/thr_read.c | 11 | ||||
-rw-r--r-- | lib/libkse/thread/thr_readv.c | 7 | ||||
-rw-r--r-- | lib/libkse/thread/thr_select.c | 12 | ||||
-rw-r--r-- | lib/libkse/thread/thr_sig.c | 20 | ||||
-rw-r--r-- | lib/libkse/thread/thr_spec.c | 39 | ||||
-rw-r--r-- | lib/libkse/thread/thr_write.c | 11 | ||||
-rw-r--r-- | lib/libkse/thread/thr_writev.c | 9 |
13 files changed, 94 insertions, 87 deletions
diff --git a/lib/libkse/thread/thr_close.c b/lib/libkse/thread/thr_close.c index 5678e2e..7e21853 100644 --- a/lib/libkse/thread/thr_close.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_cond.c b/lib/libkse/thread/thr_cond.c index cb08853..fae12eb 100644 --- a/lib/libkse/thread/thr_cond.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_fcntl.c b/lib/libkse/thread/thr_fcntl.c index 9a50c1c..556bd1f 100644 --- a/lib/libkse/thread/thr_fcntl.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_fsync.c b/lib/libkse/thread/thr_fsync.c index 5658c73..9141d47 100644 --- a/lib/libkse/thread/thr_fsync.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_info.c b/lib/libkse/thread/thr_info.c index c2c3426..16562ac 100644 --- a/lib/libkse/thread/thr_info.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_mutex.c b/lib/libkse/thread/thr_mutex.c index fb737cf..95c2083 100644 --- a/lib/libkse/thread/thr_mutex.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_read.c b/lib/libkse/thread/thr_read.c index 76df2cf..358a620 100644 --- a/lib/libkse/thread/thr_read.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_readv.c b/lib/libkse/thread/thr_readv.c index 10d1a43..0a19290b 100644 --- a/lib/libkse/thread/thr_readv.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_select.c b/lib/libkse/thread/thr_select.c index 96df9c1..0211883 100644 --- a/lib/libkse/thread/thr_select.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_sig.c b/lib/libkse/thread/thr_sig.c index c0fbfd1..43ef9e6 100644 --- a/lib/libkse/thread/thr_sig.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_spec.c b/lib/libkse/thread/thr_spec.c index eaad36d..745a145 100644 --- a/lib/libkse/thread/thr_spec.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_write.c b/lib/libkse/thread/thr_write.c index 773f615..78940e2 100644 --- a/lib/libkse/thread/thr_write.c +++ b/lib/libkse/thread/thr_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/libkse/thread/thr_writev.c b/lib/libkse/thread/thr_writev.c index 26a6006..9810aca 100644 --- a/lib/libkse/thread/thr_writev.c +++ b/lib/libkse/thread/thr_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: */ |