summaryrefslogtreecommitdiff
path: root/lib/libc_r
diff options
context:
space:
mode:
authorcvs2svn <cvs2svn@FreeBSD.org>1999-01-21 00:55:32 +0000
committercvs2svn <cvs2svn@FreeBSD.org>1999-01-21 00:55:32 +0000
commit76b5366091f76c9bc73570149ef5055648fc2c39 (patch)
tree590d020e0f2a5bea6e09d66d951a674443b21d67 /lib/libc_r
parent4b4d01da6f07f7754ff6a6e4f5223e9f0984d1a6 (diff)
Diffstat (limited to 'lib/libc_r')
-rw-r--r--lib/libc_r/Makefile4
-rw-r--r--lib/libc_r/uthread/pthread_private.h4
-rw-r--r--lib/libc_r/uthread/uthread_cond.c55
-rw-r--r--lib/libc_r/uthread/uthread_info.c29
-rw-r--r--lib/libc_r/uthread/uthread_kern.c18
-rw-r--r--lib/libc_r/uthread/uthread_kill.c20
-rw-r--r--lib/libc_r/uthread/uthread_mattr_kind_np.c14
-rw-r--r--lib/libc_r/uthread/uthread_mutex.c85
8 files changed, 64 insertions, 165 deletions
diff --git a/lib/libc_r/Makefile b/lib/libc_r/Makefile
index 806cd10b5fa5a..84497f23658bc 100644
--- a/lib/libc_r/Makefile
+++ b/lib/libc_r/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.13 1998/06/14 11:25:44 peter Exp $
+# $Id: Makefile,v 1.12 1998/06/12 02:21:27 jb Exp $
#
# All library objects contain rcsid strings by default; they may be
# excluded as a space-saving measure. To produce a library that does
@@ -26,7 +26,7 @@ HIDDEN_SYSCALLS= accept.o bind.o close.o connect.o dup.o dup2.o \
execve.o fchflags.o fchmod.o fchown.o fcntl.o \
flock.o fpathconf.o fstat.o fstatfs.o fsync.o getdirentries.o \
getpeername.o getsockname.o getsockopt.o ioctl.o listen.o \
- nanosleep.o nfssvc.o open.o poll.o read.o readv.o recvfrom.o \
+ mknod.o nanosleep.o nfssvc.o open.o poll.o read.o readv.o recvfrom.o \
recvmsg.o sched_yield.o select.o sendmsg.o sendto.o \
setsockopt.o shutdown.o sigaction.o sigaltstack.o \
signanosleep.o socket.o socketpair.o wait4.o write.o writev.o
diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h
index 2d7e723bbfa1e..04600cfbb3beb 100644
--- a/lib/libc_r/uthread/pthread_private.h
+++ b/lib/libc_r/uthread/pthread_private.h
@@ -447,7 +447,7 @@ struct pthread {
int signo;
/* Miscellaneous data. */
- int flags;
+ char flags;
#define PTHREAD_EXITING 0x0100
char pthread_priority;
void *ret;
@@ -654,8 +654,6 @@ void _thread_dump_info(void);
void _thread_init(void);
void _thread_kern_sched(struct sigcontext *);
void _thread_kern_sched_state(enum pthread_state,char *fname,int lineno);
-void _thread_kern_sched_state_unlock(enum pthread_state state,
- spinlock_t *lock, char *fname, int lineno);
void _thread_kern_set_timeout(struct timespec *);
void _thread_sig_handler(int, int, struct sigcontext *);
void _thread_start(void);
diff --git a/lib/libc_r/uthread/uthread_cond.c b/lib/libc_r/uthread/uthread_cond.c
index a085ea60fa899..fae12ebb68b52 100644
--- a/lib/libc_r/uthread/uthread_cond.c
+++ b/lib/libc_r/uthread/uthread_cond.c
@@ -144,9 +144,6 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
switch ((*cond)->c_type) {
/* Fast condition variable: */
case COND_TYPE_FAST:
- /* Wait forever: */
- _thread_run->wakeup_time.tv_sec = -1;
-
/*
* Queue the running thread for the condition
* variable:
@@ -154,36 +151,34 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
_thread_queue_enq(&(*cond)->c_queue, _thread_run);
/* Unlock the mutex: */
- if ((rval = pthread_mutex_unlock(mutex)) != 0) {
- /*
- * Cannot unlock the mutex, so remove the
- * running thread from the condition
- * variable queue:
- */
- _thread_queue_deq(&(*cond)->c_queue);
+ pthread_mutex_unlock(mutex);
- /* Unlock the condition variable structure: */
- _SPINUNLOCK(&(*cond)->lock);
- } else {
- /* Schedule the next thread: */
- _thread_kern_sched_state_unlock(PS_COND_WAIT,
- &(*cond)->lock, __FILE__, __LINE__);
+ /* Wait forever: */
+ _thread_run->wakeup_time.tv_sec = -1;
- /* Lock the mutex: */
- rval = pthread_mutex_lock(mutex);
- }
+ /* Unlock the condition variable structure: */
+ _SPINUNLOCK(&(*cond)->lock);
+
+ /* Schedule the next thread: */
+ _thread_kern_sched_state(PS_COND_WAIT,
+ __FILE__, __LINE__);
+
+ /* Lock the condition variable structure: */
+ _SPINLOCK(&(*cond)->lock);
+
+ /* Lock the mutex: */
+ rval = pthread_mutex_lock(mutex);
break;
/* Trap invalid condition variable types: */
default:
- /* Unlock the condition variable structure: */
- _SPINUNLOCK(&(*cond)->lock);
-
/* Return an invalid argument error: */
rval = EINVAL;
break;
}
+ /* Unlock the condition variable structure: */
+ _SPINUNLOCK(&(*cond)->lock);
}
/* Return the completion status: */
@@ -234,13 +229,16 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
* variable queue:
*/
_thread_queue_deq(&(*cond)->c_queue);
-
+ } else {
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
- } else {
+
/* Schedule the next thread: */
- _thread_kern_sched_state_unlock(PS_COND_WAIT,
- &(*cond)->lock, __FILE__, __LINE__);
+ _thread_kern_sched_state(PS_COND_WAIT,
+ __FILE__, __LINE__);
+
+ /* Lock the condition variable structure: */
+ _SPINLOCK(&(*cond)->lock);
/* Lock the mutex: */
if ((rval = pthread_mutex_lock(mutex)) != 0) {
@@ -255,14 +253,13 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Trap invalid condition variable types: */
default:
- /* Unlock the condition variable structure: */
- _SPINUNLOCK(&(*cond)->lock);
-
/* Return an invalid argument error: */
rval = EINVAL;
break;
}
+ /* Unlock the condition variable structure: */
+ _SPINUNLOCK(&(*cond)->lock);
}
/* Return the completion status: */
diff --git a/lib/libc_r/uthread/uthread_info.c b/lib/libc_r/uthread/uthread_info.c
index f66dd2d6ddcf4..07877d167e337 100644
--- a/lib/libc_r/uthread/uthread_info.c
+++ b/lib/libc_r/uthread/uthread_info.c
@@ -36,7 +36,6 @@
#include <unistd.h>
#ifdef _THREAD_SAFE
#include <pthread.h>
-#include <errno.h>
#include "pthread_private.h"
struct s_thread_info {
@@ -74,31 +73,11 @@ _thread_dump_info(void)
int i;
int j;
pthread_t pthread;
- char tmpfile[128];
- for (i = 0; i < 100000; i++) {
- snprintf(tmpfile, sizeof(tmpfile), "/tmp/uthread.dump.%u.%i",
- getpid(), i);
- /* Open the dump file for append and create it if necessary: */
- if ((fd = _thread_sys_open(tmpfile, O_RDWR | O_CREAT | O_EXCL,
- 0666)) < 0) {
- /* Can't open the dump file. */
- if (errno == EEXIST)
- continue;
- /*
- * We only need to continue in case of
- * EEXIT error. Most other error
- * codes means that we will fail all
- * the times.
- */
- return;
- } else {
- break;
- }
- }
- if (i==100000) {
- /* all 100000 possibilities are in use :( */
- return;
+ /* Open the dump file for append and create it if necessary: */
+ if ((fd = _thread_sys_open("/tmp/uthread.dump",
+ O_RDWR | O_CREAT | O_APPEND, 0666)) < 0) {
+ /* Can't open the dump file. */
} else {
/* Output a header for active threads: */
strcpy(s, "\n\n=============\nACTIVE THREADS\n\n");
diff --git a/lib/libc_r/uthread/uthread_kern.c b/lib/libc_r/uthread/uthread_kern.c
index 3a6966bad5bf3..22746c7d211e1 100644
--- a/lib/libc_r/uthread/uthread_kern.c
+++ b/lib/libc_r/uthread/uthread_kern.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: uthread_kern.c,v 1.14 1998/10/09 19:01:30 dt Exp $
+ * $Id: uthread_kern.c,v 1.13 1998/09/30 06:36:56 jb Exp $
*
*/
#include <errno.h>
@@ -616,22 +616,6 @@ _thread_kern_sched_state(enum pthread_state state, char *fname, int lineno)
return;
}
-void
-_thread_kern_sched_state_unlock(enum pthread_state state,
- spinlock_t *lock, char *fname, int lineno)
-{
- /* Change the state of the current thread: */
- _thread_run->state = state;
- _thread_run->fname = fname;
- _thread_run->lineno = lineno;
-
- _SPINUNLOCK(lock);
-
- /* Schedule the next thread that is ready: */
- _thread_kern_sched(NULL);
- return;
-}
-
static void
_thread_kern_select(int wait_reqd)
{
diff --git a/lib/libc_r/uthread/uthread_kill.c b/lib/libc_r/uthread/uthread_kill.c
index 7572c05faff73..292ba5caf8f2c 100644
--- a/lib/libc_r/uthread/uthread_kill.c
+++ b/lib/libc_r/uthread/uthread_kill.c
@@ -83,26 +83,6 @@ pthread_kill(pthread_t pthread, int sig)
sigaddset(&pthread->sigpend,sig);
break;
- case PS_SELECT_WAIT:
- case PS_FDR_WAIT:
- case PS_FDW_WAIT:
- case PS_SLEEP_WAIT:
- if (!sigismember(&pthread->sigmask, sig) &&
- (_thread_sigact[sig - 1].sa_handler != SIG_IGN)) {
- /* Flag the operation as interrupted: */
- pthread->interrupted = 1;
-
- /* Change the state of the thread to run: */
- PTHREAD_NEW_STATE(pthread,PS_RUNNING);
-
- /* Return the signal number: */
- pthread->signo = sig;
- } else {
- /* Increment the pending signal count: */
- sigaddset(&pthread->sigpend,sig);
- }
- break;
-
default:
/* Increment the pending signal count: */
sigaddset(&pthread->sigpend,sig);
diff --git a/lib/libc_r/uthread/uthread_mattr_kind_np.c b/lib/libc_r/uthread/uthread_mattr_kind_np.c
index c145a1f899277..3eeabff038a73 100644
--- a/lib/libc_r/uthread/uthread_mattr_kind_np.c
+++ b/lib/libc_r/uthread/uthread_mattr_kind_np.c
@@ -61,18 +61,4 @@ pthread_mutexattr_getkind_np(pthread_mutexattr_t attr)
}
return(ret);
}
-
-int
-pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
-{
- int ret;
- if (attr == NULL || *attr == NULL || type >= MUTEX_TYPE_MAX) {
- errno = EINVAL;
- ret = -1;
- } else {
- (*attr)->m_type = type;
- ret = 0;
- }
- return(ret);
-}
#endif
diff --git a/lib/libc_r/uthread/uthread_mutex.c b/lib/libc_r/uthread/uthread_mutex.c
index d3801f1750c0b..4f4aa8af041e6 100644
--- a/lib/libc_r/uthread/uthread_mutex.c
+++ b/lib/libc_r/uthread/uthread_mutex.c
@@ -53,7 +53,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
/* Check if default mutex attributes: */
if (mutex_attr == NULL || *mutex_attr == NULL)
/* Default to a fast mutex: */
- type = PTHREAD_MUTEX_DEFAULT;
+ type = MUTEX_TYPE_FAST;
else if ((*mutex_attr)->m_type >= MUTEX_TYPE_MAX)
/* Return an invalid argument error: */
@@ -74,14 +74,12 @@ pthread_mutex_init(pthread_mutex_t * mutex,
/* Process according to mutex type: */
switch (type) {
/* Fast mutex: */
- case PTHREAD_MUTEX_DEFAULT:
- case PTHREAD_MUTEX_NORMAL:
- case PTHREAD_MUTEX_ERRORCHECK:
+ case MUTEX_TYPE_FAST:
/* Nothing to do here. */
break;
/* Counting mutex: */
- case PTHREAD_MUTEX_RECURSIVE:
+ case MUTEX_TYPE_COUNTING_FAST:
/* Reset the mutex count: */
pmutex->m_data.m_count = 0;
break;
@@ -176,9 +174,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
/* Process according to mutex type: */
switch ((*mutex)->m_type) {
/* Fast mutex: */
- case PTHREAD_MUTEX_NORMAL:
- case PTHREAD_MUTEX_DEFAULT:
- case PTHREAD_MUTEX_ERRORCHECK:
+ case MUTEX_TYPE_FAST:
/* Check if this mutex is not locked: */
if ((*mutex)->m_owner == NULL) {
/* Lock the mutex for the running thread: */
@@ -190,7 +186,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
break;
/* Counting mutex: */
- case PTHREAD_MUTEX_RECURSIVE:
+ case MUTEX_TYPE_COUNTING_FAST:
/* Check if this mutex is locked: */
if ((*mutex)->m_owner != NULL) {
/*
@@ -243,26 +239,8 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
/* Process according to mutex type: */
switch ((*mutex)->m_type) {
- /* What SS2 define as a 'normal' mutex. This has to deadlock
- on attempts to get a lock you already own. */
- case PTHREAD_MUTEX_NORMAL:
- if ((*mutex)->m_owner == _thread_run) {
- /* Intetionally deadlock */
- for (;;)
- _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__);
- }
- goto COMMON_LOCK;
-
- /* Return error (not OK) on attempting to re-lock */
- case PTHREAD_MUTEX_ERRORCHECK:
- if ((*mutex)->m_owner == _thread_run) {
- ret = EDEADLK;
- break;
- }
-
/* Fast mutexes do not check for any error conditions: */
- case PTHREAD_MUTEX_DEFAULT:
- COMMON_LOCK:
+ case MUTEX_TYPE_FAST:
/*
* Enter a loop to wait for the mutex to be locked by the
* current thread:
@@ -279,10 +257,11 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
*/
_thread_queue_enq(&(*mutex)->m_queue, _thread_run);
- /* Wait for the mutex: */
- _thread_kern_sched_state_unlock(
- PS_MUTEX_WAIT, &(*mutex)->lock,
- __FILE__, __LINE__);
+ /* Unlock the mutex structure: */
+ _SPINUNLOCK(&(*mutex)->lock);
+
+ /* Block signals: */
+ _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__);
/* Lock the mutex again: */
_SPINLOCK(&(*mutex)->lock);
@@ -291,7 +270,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
break;
/* Counting mutex: */
- case PTHREAD_MUTEX_RECURSIVE:
+ case MUTEX_TYPE_COUNTING_FAST:
/*
* Enter a loop to wait for the mutex to be locked by the
* current thread:
@@ -311,10 +290,11 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
*/
_thread_queue_enq(&(*mutex)->m_queue, _thread_run);
- /* Wait for the mutex: */
- _thread_kern_sched_state_unlock(
- PS_MUTEX_WAIT, &(*mutex)->lock,
- __FILE__, __LINE__);
+ /* Unlock the mutex structure: */
+ _SPINUNLOCK(&(*mutex)->lock);
+
+ /* Block signals: */
+ _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__);
/* Lock the mutex again: */
_SPINLOCK(&(*mutex)->lock);
@@ -353,15 +333,12 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Process according to mutex type: */
switch ((*mutex)->m_type) {
- /* Default & normal mutexes do not really need to check for
- any error conditions: */
- case PTHREAD_MUTEX_NORMAL:
- case PTHREAD_MUTEX_DEFAULT:
- case PTHREAD_MUTEX_ERRORCHECK:
+ /* Fast mutexes do not check for any error conditions: */
+ case MUTEX_TYPE_FAST:
/* Check if the running thread is not the owner of the mutex: */
if ((*mutex)->m_owner != _thread_run) {
/* Return an invalid argument error: */
- ret = (*mutex)->m_owner ? EPERM : EINVAL;
+ ret = EINVAL;
}
/*
* Get the next thread from the queue of threads waiting on
@@ -374,26 +351,24 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
break;
/* Counting mutex: */
- case PTHREAD_MUTEX_RECURSIVE:
+ case MUTEX_TYPE_COUNTING_FAST:
/* Check if the running thread is not the owner of the mutex: */
if ((*mutex)->m_owner != _thread_run) {
/* Return an invalid argument error: */
ret = EINVAL;
}
/* Check if there are still counts: */
- else if ((*mutex)->m_data.m_count > 1) {
+ else if ((*mutex)->m_data.m_count) {
/* Decrement the count: */
(*mutex)->m_data.m_count--;
- } else {
- (*mutex)->m_data.m_count = 0;
- /*
- * Get the next thread from the queue of threads waiting on
- * the mutex:
- */
- if (((*mutex)->m_owner = _thread_queue_deq(&(*mutex)->m_queue)) != NULL) {
- /* Allow the new owner of the mutex to run: */
- PTHREAD_NEW_STATE((*mutex)->m_owner,PS_RUNNING);
- }
+ }
+ /*
+ * Get the next thread from the queue of threads waiting on
+ * the mutex:
+ */
+ else if (((*mutex)->m_owner = _thread_queue_deq(&(*mutex)->m_queue)) != NULL) {
+ /* Allow the new owner of the mutex to run: */
+ PTHREAD_NEW_STATE((*mutex)->m_owner,PS_RUNNING);
}
break;