summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc_r/uthread/pthread_private.h12
-rw-r--r--lib/libc_r/uthread/uthread_accept.c13
-rw-r--r--lib/libc_r/uthread/uthread_cancel.c31
-rw-r--r--lib/libc_r/uthread/uthread_clean.c12
-rw-r--r--lib/libc_r/uthread/uthread_cond.c26
-rw-r--r--lib/libc_r/uthread/uthread_connect.c5
-rw-r--r--lib/libc_r/uthread/uthread_create.c15
-rw-r--r--lib/libc_r/uthread/uthread_execve.c5
-rw-r--r--lib/libc_r/uthread/uthread_exit.c27
-rw-r--r--lib/libc_r/uthread/uthread_fd.c54
-rw-r--r--lib/libc_r/uthread/uthread_fork.c11
-rw-r--r--lib/libc_r/uthread/uthread_gc.c11
-rw-r--r--lib/libc_r/uthread/uthread_info.c5
-rw-r--r--lib/libc_r/uthread/uthread_join.c7
-rw-r--r--lib/libc_r/uthread/uthread_kern.c90
-rw-r--r--lib/libc_r/uthread/uthread_kevent.c17
-rw-r--r--lib/libc_r/uthread/uthread_nanosleep.c17
-rw-r--r--lib/libc_r/uthread/uthread_poll.c9
-rw-r--r--lib/libc_r/uthread/uthread_read.c9
-rw-r--r--lib/libc_r/uthread/uthread_readv.c9
-rw-r--r--lib/libc_r/uthread/uthread_recvfrom.c9
-rw-r--r--lib/libc_r/uthread/uthread_recvmsg.c9
-rw-r--r--lib/libc_r/uthread/uthread_select.c21
-rw-r--r--lib/libc_r/uthread/uthread_self.c4
-rw-r--r--lib/libc_r/uthread/uthread_sendmsg.c9
-rw-r--r--lib/libc_r/uthread/uthread_sendto.c9
-rw-r--r--lib/libc_r/uthread/uthread_sig.c29
-rw-r--r--lib/libc_r/uthread/uthread_sigmask.c11
-rw-r--r--lib/libc_r/uthread/uthread_sigpending.c5
-rw-r--r--lib/libc_r/uthread/uthread_sigsuspend.c13
-rw-r--r--lib/libc_r/uthread/uthread_sigwait.c13
-rw-r--r--lib/libc_r/uthread/uthread_single_np.c6
-rw-r--r--lib/libc_r/uthread/uthread_spec.c31
-rw-r--r--lib/libc_r/uthread/uthread_spinlock.c15
-rw-r--r--lib/libc_r/uthread/uthread_wait4.c7
-rw-r--r--lib/libc_r/uthread/uthread_write.c9
-rw-r--r--lib/libc_r/uthread/uthread_writev.c9
-rw-r--r--lib/libc_r/uthread/uthread_yield.c10
-rw-r--r--lib/libpthread/uthread/pthread_private.h12
-rw-r--r--lib/libpthread/uthread/uthread_accept.c13
-rw-r--r--lib/libpthread/uthread/uthread_cancel.c31
-rw-r--r--lib/libpthread/uthread/uthread_clean.c12
-rw-r--r--lib/libpthread/uthread/uthread_cond.c26
-rw-r--r--lib/libpthread/uthread/uthread_connect.c5
-rw-r--r--lib/libpthread/uthread/uthread_create.c15
-rw-r--r--lib/libpthread/uthread/uthread_execve.c5
-rw-r--r--lib/libpthread/uthread/uthread_exit.c27
-rw-r--r--lib/libpthread/uthread/uthread_fd.c54
-rw-r--r--lib/libpthread/uthread/uthread_fork.c11
-rw-r--r--lib/libpthread/uthread/uthread_gc.c11
-rw-r--r--lib/libpthread/uthread/uthread_info.c5
-rw-r--r--lib/libpthread/uthread/uthread_join.c7
-rw-r--r--lib/libpthread/uthread/uthread_kern.c90
-rw-r--r--lib/libpthread/uthread/uthread_kevent.c17
-rw-r--r--lib/libpthread/uthread/uthread_nanosleep.c17
-rw-r--r--lib/libpthread/uthread/uthread_poll.c9
-rw-r--r--lib/libpthread/uthread/uthread_read.c9
-rw-r--r--lib/libpthread/uthread/uthread_readv.c9
-rw-r--r--lib/libpthread/uthread/uthread_recvfrom.c9
-rw-r--r--lib/libpthread/uthread/uthread_recvmsg.c9
-rw-r--r--lib/libpthread/uthread/uthread_select.c21
-rw-r--r--lib/libpthread/uthread/uthread_self.c4
-rw-r--r--lib/libpthread/uthread/uthread_sendmsg.c9
-rw-r--r--lib/libpthread/uthread/uthread_sendto.c9
-rw-r--r--lib/libpthread/uthread/uthread_sig.c29
-rw-r--r--lib/libpthread/uthread/uthread_sigmask.c11
-rw-r--r--lib/libpthread/uthread/uthread_sigpending.c5
-rw-r--r--lib/libpthread/uthread/uthread_sigsuspend.c13
-rw-r--r--lib/libpthread/uthread/uthread_sigwait.c13
-rw-r--r--lib/libpthread/uthread/uthread_single_np.c6
-rw-r--r--lib/libpthread/uthread/uthread_spec.c31
-rw-r--r--lib/libpthread/uthread/uthread_spinlock.c15
-rw-r--r--lib/libpthread/uthread/uthread_wait4.c7
-rw-r--r--lib/libpthread/uthread/uthread_write.c9
-rw-r--r--lib/libpthread/uthread/uthread_writev.c9
-rw-r--r--lib/libpthread/uthread/uthread_yield.c10
76 files changed, 690 insertions, 518 deletions
diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h
index cff1cba3e90..71b013db60e 100644
--- a/lib/libc_r/uthread/pthread_private.h
+++ b/lib/libc_r/uthread/pthread_private.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pthread_private.h,v 1.22 2001/08/15 23:50:34 fgsch Exp $ */
+/* $OpenBSD: pthread_private.h,v 1.23 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -278,7 +278,7 @@ struct pthread_mutex_attr {
*/
enum pthread_cond_type {
COND_TYPE_FAST,
-#define COND_TYPE_MAX ((int)COND_TYPE_FAST + 1)
+ COND_TYPE_MAX
};
struct pthread_cond {
@@ -287,6 +287,7 @@ struct pthread_cond {
pthread_mutex_t c_mutex;
void *c_data;
long c_flags;
+ int c_seqno;
/*
* Lock for accesses to this structure.
@@ -333,6 +334,7 @@ struct pthread_attr {
void (*cleanup_attr) ();
void *stackaddr_attr;
size_t stacksize_attr;
+ size_t guardsize_attr;
};
/*
@@ -409,8 +411,8 @@ enum pthread_state {
PS_JOIN,
PS_SUSPENDED,
PS_DEAD,
- PS_DEADLOCK
-#define PS_STATE_MAX ((int)PS_DEADLOCK + 1)
+ PS_DEADLOCK,
+ PS_STATE_MAX
};
@@ -803,6 +805,8 @@ extern int _thread_kern_new_state;
__BEGIN_DECLS
int _find_dead_thread(pthread_t);
int _find_thread(pthread_t);
+struct pthread *_get_curthread(void);
+void _set_curthread(struct pthread *);
int _thread_create(pthread_t *,const pthread_attr_t *,void *(*start_routine)(void *),void *,pthread_t);
void _dispatch_signals(void);
void _thread_signal(pthread_t, int);
diff --git a/lib/libc_r/uthread/uthread_accept.c b/lib/libc_r/uthread/uthread_accept.c
index db8d078c444..23197f8dadc 100644
--- a/lib/libc_r/uthread/uthread_accept.c
+++ b/lib/libc_r/uthread/uthread_accept.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_accept.c,v 1.4 1999/11/25 07:01:30 d Exp $ */
+/* $OpenBSD: uthread_accept.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -44,6 +44,7 @@
int
accept(int fd, struct sockaddr * name, socklen_t *namelen)
{
+ struct pthread *curthread = _get_curthread();
int ret;
/* Lock the file descriptor: */
@@ -53,19 +54,19 @@ accept(int fd, struct sockaddr * name, socklen_t *namelen)
/* Check if the socket is to block: */
if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && (errno == EWOULDBLOCK || errno == EAGAIN)) {
/* Save the socket file descriptor: */
- _thread_run->data.fd.fd = fd;
- _thread_run->data.fd.fname = __FILE__;
- _thread_run->data.fd.branch = __LINE__;
+ curthread->data.fd.fd = fd;
+ curthread->data.fd.fname = __FILE__;
+ curthread->data.fd.branch = __LINE__;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
/* Schedule the next thread: */
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
/* Check if the wait was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error status: */
errno = EINTR;
ret = -1;
diff --git a/lib/libc_r/uthread/uthread_cancel.c b/lib/libc_r/uthread/uthread_cancel.c
index e43e03bf00b..7428ee07ecb 100644
--- a/lib/libc_r/uthread/uthread_cancel.c
+++ b/lib/libc_r/uthread/uthread_cancel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_cancel.c,v 1.2 1999/11/25 07:01:32 d Exp $ */
+/* $OpenBSD: uthread_cancel.c,v 1.3 2001/08/21 19:24:53 fgsch Exp $ */
/*
* David Leonard <d@openbsd.org>, 1999. Public domain.
*/
@@ -64,24 +64,25 @@ pthread_setcancelstate(state, oldstate)
int state;
int *oldstate;
{
+ struct pthread *curthread = _get_curthread();
int ostate;
int ret;
- ostate = _thread_run->cancelstate;
+ ostate = curthread->cancelstate;
switch (state) {
case PTHREAD_CANCEL_ENABLE:
if (oldstate)
*oldstate = ostate;
- _thread_run->cancelstate = PTHREAD_CANCEL_ENABLE;
- if (_thread_run->canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)
+ curthread->cancelstate = PTHREAD_CANCEL_ENABLE;
+ if (curthread->canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)
_thread_cancellation_point();
ret = 0;
break;
case PTHREAD_CANCEL_DISABLE:
if (oldstate)
*oldstate = ostate;
- _thread_run->cancelstate = PTHREAD_CANCEL_DISABLE;
+ curthread->cancelstate = PTHREAD_CANCEL_DISABLE;
ret = 0;
break;
default:
@@ -97,22 +98,23 @@ pthread_setcanceltype(type, oldtype)
int type;
int *oldtype;
{
+ struct pthread *curthread = _get_curthread();
int otype;
int ret;
- otype = _thread_run->canceltype;
+ otype = curthread->canceltype;
switch (type) {
case PTHREAD_CANCEL_ASYNCHRONOUS:
if (oldtype)
*oldtype = otype;
- _thread_run->canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
+ curthread->canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
_thread_cancellation_point();
ret = 0;
break;
case PTHREAD_CANCEL_DEFERRED:
if (oldtype)
*oldtype = otype;
- _thread_run->canceltype = PTHREAD_CANCEL_DEFERRED;
+ curthread->canceltype = PTHREAD_CANCEL_DEFERRED;
ret = 0;
break;
default:
@@ -132,17 +134,19 @@ pthread_testcancel()
void
_thread_enter_cancellation_point()
{
+ struct pthread *curthread = _get_curthread();
/* Look for a cancellation before we block: */
_thread_cancellation_point();
- _thread_run->flags |= PTHREAD_FLAGS_CANCELPT;
+ curthread->flags |= PTHREAD_FLAGS_CANCELPT;
}
void
_thread_leave_cancellation_point()
{
+ struct pthread *curthread = _get_curthread();
- _thread_run->flags &=~ PTHREAD_FLAGS_CANCELPT;
+ curthread->flags &=~ PTHREAD_FLAGS_CANCELPT;
/* Look for a cancellation after we unblock: */
_thread_cancellation_point();
}
@@ -154,11 +158,12 @@ _thread_leave_cancellation_point()
void
_thread_cancellation_point()
{
+ struct pthread *curthread = _get_curthread();
- if ((_thread_run->cancelstate == PTHREAD_CANCEL_ENABLE) &&
- ((_thread_run->flags & (PTHREAD_FLAGS_CANCELED|PTHREAD_EXITING)) ==
+ if ((curthread->cancelstate == PTHREAD_CANCEL_ENABLE) &&
+ ((curthread->flags & (PTHREAD_FLAGS_CANCELED|PTHREAD_EXITING)) ==
PTHREAD_FLAGS_CANCELED)) {
- _thread_run->flags &=~ PTHREAD_FLAGS_CANCELED;
+ curthread->flags &=~ PTHREAD_FLAGS_CANCELED;
pthread_exit(PTHREAD_CANCELED);
PANIC("cancel");
}
diff --git a/lib/libc_r/uthread/uthread_clean.c b/lib/libc_r/uthread/uthread_clean.c
index 0fc9a272f7f..ed6df7d70b6 100644
--- a/lib/libc_r/uthread/uthread_clean.c
+++ b/lib/libc_r/uthread/uthread_clean.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_clean.c,v 1.3 1999/11/25 07:01:32 d Exp $ */
+/* $OpenBSD: uthread_clean.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -42,24 +42,26 @@
void
pthread_cleanup_push(void (*routine) (void *), void *routine_arg)
{
+ struct pthread *curthread = _get_curthread();
struct pthread_cleanup *new;
if ((new = (struct pthread_cleanup *) malloc(sizeof(struct pthread_cleanup))) != NULL) {
new->routine = routine;
new->routine_arg = routine_arg;
- new->next = _thread_run->cleanup;
+ new->next = curthread->cleanup;
- _thread_run->cleanup = new;
+ curthread->cleanup = new;
}
}
void
pthread_cleanup_pop(int execute)
{
+ struct pthread *curthread = _get_curthread();
struct pthread_cleanup *old;
- if ((old = _thread_run->cleanup) != NULL) {
- _thread_run->cleanup = old->next;
+ if ((old = curthread->cleanup) != NULL) {
+ curthread->cleanup = old->next;
if (execute) {
old->routine(old->routine_arg);
}
diff --git a/lib/libc_r/uthread/uthread_cond.c b/lib/libc_r/uthread/uthread_cond.c
index 1991bb472c8..48ee72a6b2f 100644
--- a/lib/libc_r/uthread/uthread_cond.c
+++ b/lib/libc_r/uthread/uthread_cond.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_cond.c,v 1.9 2000/01/06 07:14:47 d Exp $ */
+/* $OpenBSD: uthread_cond.c,v 1.10 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -158,6 +158,7 @@ pthread_cond_destroy(pthread_cond_t * cond)
int
pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
{
+ struct pthread *curthread = _get_curthread();
int rval = 0;
/* This is a cancellation point: */
@@ -197,19 +198,19 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
rval = EINVAL;
} else {
/* Reset the timeout flag: */
- _thread_run->timeout = 0;
+ curthread->timeout = 0;
/*
* Queue the running thread for the condition
* variable:
*/
- cond_queue_enq(*cond, _thread_run);
+ cond_queue_enq(*cond, curthread);
/* Remember the mutex that is being used: */
(*cond)->c_mutex = *mutex;
/* Wait forever: */
- _thread_run->wakeup_time.tv_sec = -1;
+ curthread->wakeup_time.tv_sec = -1;
/* Unlock the mutex: */
if ((rval = _mutex_cv_unlock(mutex)) != 0) {
@@ -218,7 +219,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
* the running thread from the condition
* variable queue:
*/
- cond_queue_remove(*cond, _thread_run);
+ cond_queue_remove(*cond, curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) ==
@@ -264,6 +265,7 @@ int
pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
const struct timespec * abstime)
{
+ struct pthread *curthread = _get_curthread();
int rval = 0;
/* This is a cancellation point: */
@@ -307,19 +309,19 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
_SPINUNLOCK(&(*cond)->lock);
} else {
/* Set the wakeup time: */
- _thread_run->wakeup_time.tv_sec =
+ curthread->wakeup_time.tv_sec =
abstime->tv_sec;
- _thread_run->wakeup_time.tv_nsec =
+ curthread->wakeup_time.tv_nsec =
abstime->tv_nsec;
/* Reset the timeout flag: */
- _thread_run->timeout = 0;
+ curthread->timeout = 0;
/*
* Queue the running thread for the condition
* variable:
*/
- cond_queue_enq(*cond, _thread_run);
+ cond_queue_enq(*cond, curthread);
/* Remember the mutex that is being used: */
(*cond)->c_mutex = *mutex;
@@ -331,7 +333,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
* the running thread from the condition
* variable queue:
*/
- cond_queue_remove(*cond, _thread_run);
+ cond_queue_remove(*cond, curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
@@ -348,7 +350,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
&(*cond)->lock, __FILE__, __LINE__);
/* Check if the wait timedout: */
- if (_thread_run->timeout == 0) {
+ if (curthread->timeout == 0) {
/* Lock the mutex: */
rval = _mutex_cv_lock(mutex);
}
@@ -362,7 +364,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
* variable queue:
*/
cond_queue_remove(*cond,
- _thread_run);
+ curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
diff --git a/lib/libc_r/uthread/uthread_connect.c b/lib/libc_r/uthread/uthread_connect.c
index a6a2f367189..ad0a6ea8921 100644
--- a/lib/libc_r/uthread/uthread_connect.c
+++ b/lib/libc_r/uthread/uthread_connect.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_connect.c,v 1.3 1999/11/25 07:01:33 d Exp $ */
+/* $OpenBSD: uthread_connect.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,6 +43,7 @@
int
connect(int fd, const struct sockaddr * name, socklen_t namelen)
{
+ struct pthread *curthread = _get_curthread();
struct sockaddr tmpname;
int errnolen, ret, tmpnamelen;
@@ -51,7 +52,7 @@ connect(int fd, const struct sockaddr * name, socklen_t namelen)
if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) &&
((errno == EWOULDBLOCK) || (errno == EINPROGRESS) ||
(errno == EALREADY) || (errno == EAGAIN))) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
diff --git a/lib/libc_r/uthread/uthread_create.c b/lib/libc_r/uthread/uthread_create.c
index a1981e90f3c..82606872c1d 100644
--- a/lib/libc_r/uthread/uthread_create.c
+++ b/lib/libc_r/uthread/uthread_create.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_create.c,v 1.14 2000/10/04 05:55:35 d Exp $ */
+/* $OpenBSD: uthread_create.c,v 1.15 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -49,6 +49,7 @@ int
pthread_create(pthread_t * thread, const pthread_attr_t * attr,
void *(*start_routine) (void *), void *arg)
{
+ struct pthread *curthread = _get_curthread();
int f_gc = 0;
int ret = 0;
pthread_t gc_thread;
@@ -102,7 +103,7 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
new_thread->magic = PTHREAD_MAGIC;
/* Initialise the thread for signals: */
- new_thread->sigmask = _thread_run->sigmask;
+ new_thread->sigmask = curthread->sigmask;
/*
* Set up new stack frame so that it 'returns' to
@@ -122,11 +123,11 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
if (new_thread->attr.flags & PTHREAD_INHERIT_SCHED) {
/* Copy the scheduling attributes: */
new_thread->base_priority
- = _thread_run->base_priority;
+ = curthread->base_priority;
new_thread->attr.prio
- = _thread_run->base_priority;
+ = curthread->base_priority;
new_thread->attr.sched_policy
- = _thread_run->attr.sched_policy;
+ = curthread->attr.sched_policy;
} else {
/*
* Use just the thread priority, leaving the
@@ -205,11 +206,13 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
void
_thread_start(void)
{
+ struct pthread *curthread = _get_curthread();
+
/* We just left the scheduler via longjmp: */
_thread_kern_in_sched = 0;
/* Run the current thread's start routine with argument: */
- pthread_exit(_thread_run->start_routine(_thread_run->arg));
+ pthread_exit(curthread->start_routine(curthread->arg));
/* This point should never be reached. */
PANIC("Thread has resumed after exit");
diff --git a/lib/libc_r/uthread/uthread_execve.c b/lib/libc_r/uthread/uthread_execve.c
index b401dd1a145..d6b9c8116b5 100644
--- a/lib/libc_r/uthread/uthread_execve.c
+++ b/lib/libc_r/uthread/uthread_execve.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_execve.c,v 1.5 1999/11/25 07:01:34 d Exp $ */
+/* $OpenBSD: uthread_execve.c,v 1.6 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -42,6 +42,7 @@
int
execve(const char *name, char *const * argv, char *const * envp)
{
+ struct pthread *curthread = _get_curthread();
int flags;
int i;
int ret;
@@ -103,7 +104,7 @@ execve(const char *name, char *const * argv, char *const * envp)
}
/* Set the signal mask: */
- _thread_sys_sigprocmask(SIG_SETMASK, &_thread_run->sigmask, NULL);
+ _thread_sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
/* Execute the process: */
ret = _thread_sys_execve(name, argv, envp);
diff --git a/lib/libc_r/uthread/uthread_exit.c b/lib/libc_r/uthread/uthread_exit.c
index 8e884f70727..c6013cbf1ea 100644
--- a/lib/libc_r/uthread/uthread_exit.c
+++ b/lib/libc_r/uthread/uthread_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_exit.c,v 1.12 2000/01/06 07:16:40 d Exp $ */
+/* $OpenBSD: uthread_exit.c,v 1.13 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -145,29 +145,30 @@ _thread_exit(const char *fname, int lineno, const char *string)
void
pthread_exit(void *status)
{
+ struct pthread *curthread = _get_curthread();
pthread_t pthread;
/* Check if this thread is already in the process of exiting: */
- if ((_thread_run->flags & PTHREAD_EXITING) != 0) {
+ if ((curthread->flags & PTHREAD_EXITING) != 0) {
PANIC("Thread has called pthread_exit() from a destructor. POSIX 1003.1 1996 s16.2.5.2 does not allow this!");
}
/* Flag this thread as exiting: */
- _thread_run->flags |= PTHREAD_EXITING;
+ curthread->flags |= PTHREAD_EXITING;
/* Save the return value: */
- _thread_run->ret = status;
+ curthread->ret = status;
- while (_thread_run->cleanup != NULL) {
+ while (curthread->cleanup != NULL) {
pthread_cleanup_pop(1);
}
- if (_thread_run->attr.cleanup_attr != NULL) {
- _thread_run->attr.cleanup_attr(_thread_run->attr.arg_attr);
+ if (curthread->attr.cleanup_attr != NULL) {
+ curthread->attr.cleanup_attr(curthread->attr.arg_attr);
}
/* Check if there is thread specific data: */
- if (_thread_run->specific_data != NULL) {
+ if (curthread->specific_data != NULL) {
/* Run the thread-specific data destructors: */
_thread_cleanupspecific();
}
@@ -179,9 +180,9 @@ pthread_exit(void *status)
_thread_kern_sig_defer();
/* Check if there are any threads joined to this one: */
- while ((pthread = TAILQ_FIRST(&(_thread_run->join_queue))) != NULL) {
+ while ((pthread = TAILQ_FIRST(&(curthread->join_queue))) != NULL) {
/* Remove the thread from the queue: */
- TAILQ_REMOVE(&_thread_run->join_queue, pthread, qe);
+ TAILQ_REMOVE(&curthread->join_queue, pthread, qe);
/* Wake the joined thread and let it detach this thread: */
PTHREAD_NEW_STATE(pthread,PS_RUNNING);
@@ -200,7 +201,7 @@ pthread_exit(void *status)
PANIC("Cannot lock gc mutex");
/* Add this thread to the list of dead threads. */
- TAILQ_INSERT_HEAD(&_dead_list, _thread_run, dle);
+ TAILQ_INSERT_HEAD(&_dead_list, curthread, dle);
/*
* Defer signals to protect the scheduling queues from access
@@ -209,7 +210,7 @@ pthread_exit(void *status)
_thread_kern_sig_defer();
/* Remove this thread from the thread list: */
- TAILQ_REMOVE(&_thread_list, _thread_run, tle);
+ TAILQ_REMOVE(&_thread_list, curthread, tle);
/*
* Undefer and handle pending signals, yielding if necessary:
@@ -227,7 +228,7 @@ pthread_exit(void *status)
* Mark the thread as dead so it will not return if it
* gets context switched out when the mutex is unlocked.
*/
- PTHREAD_SET_STATE(_thread_run, PS_DEAD);
+ PTHREAD_SET_STATE(curthread, PS_DEAD);
/* Unlock the garbage collector mutex: */
if (pthread_mutex_unlock(&_gc_mutex) != 0)
diff --git a/lib/libc_r/uthread/uthread_fd.c b/lib/libc_r/uthread/uthread_fd.c
index 39303fc0820..b49a3cda8fb 100644
--- a/lib/libc_r/uthread/uthread_fd.c
+++ b/lib/libc_r/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
diff --git a/lib/libc_r/uthread/uthread_fork.c b/lib/libc_r/uthread/uthread_fork.c
index 5f9054a332b..0271e822526 100644
--- a/lib/libc_r/uthread/uthread_fork.c
+++ b/lib/libc_r/uthread/uthread_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_fork.c,v 1.9 2000/01/06 07:17:09 d Exp $ */
+/* $OpenBSD: uthread_fork.c,v 1.10 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -44,6 +44,7 @@
pid_t
fork(void)
{
+ struct pthread *curthread = _get_curthread();
int i, flags;
pid_t ret;
pthread_t pthread;
@@ -63,7 +64,7 @@ fork(void)
_thread_sys_close(_thread_kern_pipe[1]);
/* Reset signals pending for the running thread: */
- sigemptyset(&_thread_run->sigpend);
+ sigemptyset(&curthread->sigpend);
/*
* Create a pipe that is written to by the signal handler to
@@ -117,7 +118,7 @@ fork(void)
TAILQ_REMOVE(&_thread_list, pthread, tle);
/* Make sure this isn't the running thread: */
- if (pthread != _thread_run) {
+ if (pthread != curthread) {
/* XXX should let gc do all this. */
if(pthread->stack != NULL)
_thread_stack_free(pthread->stack);
@@ -133,7 +134,7 @@ fork(void)
}
/* Restore the running thread */
- TAILQ_INSERT_HEAD(&_thread_list, _thread_run, tle);
+ TAILQ_INSERT_HEAD(&_thread_list, curthread, tle);
/* Re-init the dead thread list: */
TAILQ_INIT(&_dead_list);
@@ -143,7 +144,7 @@ fork(void)
TAILQ_INIT(&_workq);
/* Re-init the threads mutex queue: */
- TAILQ_INIT(&_thread_run->mutexq);
+ TAILQ_INIT(&curthread->mutexq);
/* No spinlocks yet: */
_spinblock_count = 0;
diff --git a/lib/libc_r/uthread/uthread_gc.c b/lib/libc_r/uthread/uthread_gc.c
index 954a09e03df..5f4e520d6aa 100644
--- a/lib/libc_r/uthread/uthread_gc.c
+++ b/lib/libc_r/uthread/uthread_gc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_gc.c,v 1.9 2000/01/06 07:17:23 d Exp $ */
+/* $OpenBSD: uthread_gc.c,v 1.10 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -48,6 +48,7 @@
pthread_addr_t
_thread_gc(pthread_addr_t arg)
{
+ struct pthread *curthread = _get_curthread();
int f_debug;
int f_done = 0;
int ret;
@@ -62,13 +63,13 @@ _thread_gc(pthread_addr_t arg)
sigprocmask (SIG_BLOCK, &mask, NULL);
/* Mark this thread as a library thread (not a user thread). */
- _thread_run->flags |= PTHREAD_FLAGS_PRIVATE;
+ curthread->flags |= PTHREAD_FLAGS_PRIVATE;
/* Set a debug flag based on an environment variable. */
f_debug = (getenv("LIBC_R_DEBUG") != NULL);
/* Set the name of this thread. */
- pthread_set_name_np(_thread_run,"GC");
+ pthread_set_name_np(curthread,"GC");
while (!f_done) {
/* Check if debugging this application. */
@@ -83,8 +84,8 @@ _thread_gc(pthread_addr_t arg)
_thread_kern_sig_defer();
/* Check if this is the last running thread: */
- if (TAILQ_FIRST(&_thread_list) == _thread_run &&
- TAILQ_NEXT(_thread_run, tle) == NULL)
+ if (TAILQ_FIRST(&_thread_list) == curthread &&
+ TAILQ_NEXT(curthread, tle) == NULL)
/*
* This is the last thread, so it can exit
* now.
diff --git a/lib/libc_r/uthread/uthread_info.c b/lib/libc_r/uthread/uthread_info.c
index dac30c7e6c4..fc2f739962c 100644
--- a/lib/libc_r/uthread/uthread_info.c
+++ b/lib/libc_r/uthread/uthread_info.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_info.c,v 1.9 1999/11/25 06:57:04 d Exp $ */
+/* $OpenBSD: uthread_info.c,v 1.10 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -74,6 +74,7 @@ static const struct s_thread_info thread_info[] = {
void
_thread_dump_info(void)
{
+ struct pthread *curthread = _get_curthread();
char s[512];
int fd;
int i;
@@ -127,7 +128,7 @@ _thread_dump_info(void)
_thread_sys_write(fd, s, strlen(s));
/* Check if this is the running thread: */
- if (pthread == _thread_run) {
+ if (pthread == curthread) {
/* Output a record for the running thread: */
strcpy(s, "This is the running thread\n");
_thread_sys_write(fd, s, strlen(s));
diff --git a/lib/libc_r/uthread/uthread_join.c b/lib/libc_r/uthread/uthread_join.c
index 374a5d45b90..310e5521268 100644
--- a/lib/libc_r/uthread/uthread_join.c
+++ b/lib/libc_r/uthread/uthread_join.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_join.c,v 1.6 1999/11/25 07:01:37 d Exp $ */
+/* $OpenBSD: uthread_join.c,v 1.7 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -40,6 +40,7 @@
int
pthread_join(pthread_t pthread, void **thread_return)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
/* This is a cancellation point: */
@@ -51,7 +52,7 @@ pthread_join(pthread_t pthread, void **thread_return)
ret = EINVAL;
/* Check if the caller has specified itself: */
- else if (pthread == _thread_run)
+ else if (pthread == curthread)
/* Avoid a deadlock condition: */
ret = EDEADLK;
@@ -72,7 +73,7 @@ pthread_join(pthread_t pthread, void **thread_return)
/* Check if the thread is not dead: */
else if (pthread->state != PS_DEAD) {
/* Add the running thread to the join queue: */
- TAILQ_INSERT_TAIL(&(pthread->join_queue), _thread_run, qe);
+ TAILQ_INSERT_TAIL(&(pthread->join_queue), curthread, qe);
/* Schedule the next thread: */
_thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__);
diff --git a/lib/libc_r/uthread/uthread_kern.c b/lib/libc_r/uthread/uthread_kern.c
index 016dfc90a69..2376af06534 100644
--- a/lib/libc_r/uthread/uthread_kern.c
+++ b/lib/libc_r/uthread/uthread_kern.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_kern.c,v 1.12 2001/08/15 23:53:17 fgsch Exp $ */
+/* $OpenBSD: uthread_kern.c,v 1.13 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -75,6 +75,7 @@ _thread_check_cancel()
void
_thread_kern_sched(struct sigcontext * scp)
{
+ struct pthread *curthread = _get_curthread();
pthread_t pthread, pthread_h = NULL;
pthread_t old_thread_run;
struct itimerval itimer;
@@ -335,7 +336,8 @@ _thread_kern_sched(struct sigcontext * scp)
* the running thread to point to the global kernel
* thread structure:
*/
- _thread_run = &_thread_kern_thread;
+ _set_curthread(&_thread_kern_thread);
+ curthread = &_thread_kern_thread;
/* Unprotect the scheduling queues: */
_queue_signals = 0;
@@ -413,14 +415,15 @@ _thread_kern_sched(struct sigcontext * scp)
}
/* Make the selected thread the current thread: */
- _thread_run = pthread_h;
+ _set_curthread(pthread_h);
+ curthread = pthread_h;
/*
* Save the current time as the time that the thread
* became active:
*/
- _thread_run->last_active.tv_sec = tv.tv_sec;
- _thread_run->last_active.tv_usec = tv.tv_usec;
+ curthread->last_active.tv_sec = tv.tv_sec;
+ curthread->last_active.tv_usec = tv.tv_usec;
/*
* Define the maximum time before a scheduling signal
@@ -578,6 +581,8 @@ _thread_kern_sched(struct sigcontext * scp)
void
_thread_kern_sched_state(enum pthread_state state, const char *fname, int lineno)
{
+ struct pthread *curthread = _get_curthread();
+
/*
* Flag the pthread kernel as executing scheduler code
* to avoid a scheduler signal from interrupting this
@@ -592,19 +597,20 @@ _thread_kern_sched_state(enum pthread_state state, const char *fname, int lineno
_queue_signals = 1;
/* Change the state of the current thread: */
- _thread_run->state = state;
- _thread_run->fname = fname;
- _thread_run->lineno = lineno;
+ curthread->state = state;
+ curthread->fname = fname;
+ curthread->lineno = lineno;
/* Schedule the next thread that is ready: */
_thread_kern_sched(NULL);
- return;
}
void
_thread_kern_sched_state_unlock(enum pthread_state state,
spinlock_t *lock, char *fname, int lineno)
{
+ struct pthread *curthread = _get_curthread();
+
/*
* Flag the pthread kernel as executing scheduler code
* to avoid a scheduler signal from interrupting this
@@ -620,15 +626,14 @@ _thread_kern_sched_state_unlock(enum pthread_state state,
_queue_signals = 1;
/* Change the state of the current thread: */
- _thread_run->state = state;
- _thread_run->fname = fname;
- _thread_run->lineno = lineno;
+ curthread->state = state;
+ curthread->fname = fname;
+ curthread->lineno = lineno;
_SPINUNLOCK(lock);
/* Schedule the next thread that is ready: */
_thread_kern_sched(NULL);
- return;
}
static void
@@ -963,11 +968,12 @@ _thread_kern_poll(int wait_reqd)
void
_thread_kern_set_timeout(const struct timespec * timeout)
{
+ struct pthread *curthread = _get_curthread();
struct timespec current_time;
struct timeval tv;
/* Reset the timeout flag for the running thread: */
- _thread_run->timeout = 0;
+ curthread->timeout = 0;
/* Check if the thread is to wait forever: */
if (timeout == NULL) {
@@ -975,28 +981,28 @@ _thread_kern_set_timeout(const struct timespec * timeout)
* Set the wakeup time to something that can be recognised as
* different to an actual time of day:
*/
- _thread_run->wakeup_time.tv_sec = -1;
- _thread_run->wakeup_time.tv_nsec = -1;
+ curthread->wakeup_time.tv_sec = -1;
+ curthread->wakeup_time.tv_nsec = -1;
}
/* Check if no waiting is required: */
else if (timeout->tv_sec == 0 && timeout->tv_nsec == 0) {
/* Set the wake up time to 'immediately': */
- _thread_run->wakeup_time.tv_sec = 0;
- _thread_run->wakeup_time.tv_nsec = 0;
+ curthread->wakeup_time.tv_sec = 0;
+ curthread->wakeup_time.tv_nsec = 0;
} else {
/* Get the current time: */
gettimeofday(&tv, NULL);
TIMEVAL_TO_TIMESPEC(&tv, &current_time);
/* Calculate the time for the current thread to wake up: */
- _thread_run->wakeup_time.tv_sec = current_time.tv_sec + timeout->tv_sec;
- _thread_run->wakeup_time.tv_nsec = current_time.tv_nsec + timeout->tv_nsec;
+ curthread->wakeup_time.tv_sec = current_time.tv_sec + timeout->tv_sec;
+ curthread->wakeup_time.tv_nsec = current_time.tv_nsec + timeout->tv_nsec;
/* Check if the nanosecond field needs to wrap: */
- if (_thread_run->wakeup_time.tv_nsec >= 1000000000) {
+ if (curthread->wakeup_time.tv_nsec >= 1000000000) {
/* Wrap the nanosecond field: */
- _thread_run->wakeup_time.tv_sec += 1;
- _thread_run->wakeup_time.tv_nsec -= 1000000000;
+ curthread->wakeup_time.tv_sec += 1;
+ curthread->wakeup_time.tv_nsec -= 1000000000;
}
}
return;
@@ -1005,13 +1011,16 @@ _thread_kern_set_timeout(const struct timespec * timeout)
void
_thread_kern_sig_defer(void)
{
+ struct pthread *curthread = _get_curthread();
+
/* Allow signal deferral to be recursive. */
- _thread_run->sig_defer_count++;
+ curthread->sig_defer_count++;
}
void
_thread_kern_sig_undefer(void)
{
+ struct pthread *curthread = _get_curthread();
pthread_t pthread;
int need_resched = 0;
@@ -1019,20 +1028,20 @@ _thread_kern_sig_undefer(void)
* Perform checks to yield only if we are about to undefer
* signals.
*/
- if (_thread_run->sig_defer_count > 1) {
+ if (curthread->sig_defer_count > 1) {
/* Decrement the signal deferral count. */
- _thread_run->sig_defer_count--;
+ curthread->sig_defer_count--;
}
- else if (_thread_run->sig_defer_count == 1) {
+ else if (curthread->sig_defer_count == 1) {
/* Reenable signals: */
- _thread_run->sig_defer_count = 0;
+ curthread->sig_defer_count = 0;
/*
* Check if there are queued signals:
*/
while (_sigq_check_reqd != 0) {
/* Defer scheduling while we process queued signals: */
- _thread_run->sig_defer_count = 1;
+ curthread->sig_defer_count = 1;
/* Clear the flag before checking the signal queue: */
_sigq_check_reqd = 0;
@@ -1047,17 +1056,17 @@ _thread_kern_sig_undefer(void)
*/
if ((need_resched == 0) &&
(((pthread = PTHREAD_PRIOQ_FIRST()) != NULL) &&
- (pthread->active_priority > _thread_run->active_priority))) {
+ (pthread->active_priority > curthread->active_priority))) {
need_resched = 1;
}
/* Reenable signals: */
- _thread_run->sig_defer_count = 0;
+ curthread->sig_defer_count = 0;
}
/* Yield the CPU if necessary: */
- if (need_resched || _thread_run->yield_on_sig_undefer != 0) {
- _thread_run->yield_on_sig_undefer = 0;
+ if (need_resched || curthread->yield_on_sig_undefer != 0) {
+ curthread->yield_on_sig_undefer = 0;
_thread_kern_sched(NULL);
}
}
@@ -1119,4 +1128,19 @@ thread_run_switch_hook(pthread_t thread_out, pthread_t thread_in)
_sched_switch_hook(tid_out, tid_in);
}
}
+
+struct pthread *
+_get_curthread(void)
+{
+ if (_thread_initial == NULL)
+ _thread_init();
+
+ return (_thread_run);
+}
+
+void
+_set_curthread(struct pthread *newthread)
+{
+ _thread_run = newthread;
+}
#endif
diff --git a/lib/libc_r/uthread/uthread_kevent.c b/lib/libc_r/uthread/uthread_kevent.c
index 0985d05d38a..909f92366db 100644
--- a/lib/libc_r/uthread/uthread_kevent.c
+++ b/lib/libc_r/uthread/uthread_kevent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_kevent.c,v 1.1 2001/08/15 23:50:34 fgsch Exp $ */
+/* $OpenBSD: uthread_kevent.c,v 1.2 2001/08/21 19:24:53 fgsch Exp $ */
/*-
* Copyright (c) 2000 Jonathan Lemon <jlemon@flugsvamp.com>
* All rights reserved.
@@ -40,6 +40,7 @@ int
kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents, const struct timespec *timeout)
{
+ struct pthread *curthread = _get_curthread();
struct timespec nullts = { 0, 0 };
int rc;
@@ -51,26 +52,26 @@ kevent(int kq, const struct kevent *changelist, int nchanges,
if (rc == 0 && (timeout == NULL ||
timeout->tv_sec != 0 || timeout->tv_nsec != 0)) {
/* Save the socket file descriptor: */
- _thread_run->data.fd.fd = kq;
- _thread_run->data.fd.fname = __FILE__;
- _thread_run->data.fd.branch = __LINE__;
+ curthread->data.fd.fd = kq;
+ curthread->data.fd.fname = __FILE__;
+ curthread->data.fd.branch = __LINE__;
do {
/* Reset the interrupted and timeout flags: */
- _thread_run->interrupted = 0;
- _thread_run->timeout = 0;
+ curthread->interrupted = 0;
+ curthread->timeout = 0;
_thread_kern_sched_state(PS_FDR_WAIT,
__FILE__, __LINE__);
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
rc = -1;
break;
}
rc = _thread_sys_kevent(kq, NULL, 0,
eventlist, nevents, &nullts);
- } while (rc == 0 && _thread_run->timeout == 0);
+ } while (rc == 0 && curthread->timeout == 0);
}
return (rc);
}
diff --git a/lib/libc_r/uthread/uthread_nanosleep.c b/lib/libc_r/uthread/uthread_nanosleep.c
index 583e94e983f..4518a13e91c 100644
--- a/lib/libc_r/uthread/uthread_nanosleep.c
+++ b/lib/libc_r/uthread/uthread_nanosleep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_nanosleep.c,v 1.5 1999/11/25 07:01:40 d Exp $ */
+/* $OpenBSD: uthread_nanosleep.c,v 1.6 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -42,6 +42,7 @@ int
nanosleep(const struct timespec * time_to_sleep,
struct timespec * time_remaining)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
struct timespec current_time;
struct timespec current_time1;
@@ -63,16 +64,16 @@ nanosleep(const struct timespec * time_to_sleep,
TIMEVAL_TO_TIMESPEC(&tv, &current_time);
/* Calculate the time for the current thread to wake up: */
- _thread_run->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec;
- _thread_run->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec;
+ curthread->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec;
+ curthread->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec;
/* Check if the nanosecond field has overflowed: */
- if (_thread_run->wakeup_time.tv_nsec >= 1000000000) {
+ if (curthread->wakeup_time.tv_nsec >= 1000000000) {
/* Wrap the nanosecond field: */
- _thread_run->wakeup_time.tv_sec += 1;
- _thread_run->wakeup_time.tv_nsec -= 1000000000;
+ curthread->wakeup_time.tv_sec += 1;
+ curthread->wakeup_time.tv_nsec -= 1000000000;
}
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
/* Reschedule the current thread to sleep: */
_thread_kern_sched_state(PS_SLEEP_WAIT, __FILE__, __LINE__);
@@ -114,7 +115,7 @@ nanosleep(const struct timespec * time_to_sleep,
}
/* Check if the sleep was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an EINTR error : */
errno = EINTR;
ret = -1;
diff --git a/lib/libc_r/uthread/uthread_poll.c b/lib/libc_r/uthread/uthread_poll.c
index 022b46f308b..6119eda2f34 100644
--- a/lib/libc_r/uthread/uthread_poll.c
+++ b/lib/libc_r/uthread/uthread_poll.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_poll.c,v 1.5 2001/08/15 15:47:56 fgsch Exp $ */
+/* $OpenBSD: uthread_poll.c,v 1.6 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1999 Daniel Eischen <eischen@vigrid.com>
* All rights reserved.
@@ -47,6 +47,7 @@
int
poll(struct pollfd fds[], int nfds, int timeout)
{
+ struct pthread *curthread = _get_curthread();
struct timespec ts;
int numfds = nfds;
int i, ret = 0;
@@ -84,10 +85,10 @@ poll(struct pollfd fds[], int nfds, int timeout)
fds[i].revents = 0;
}
- _thread_run->data.poll_data = &data;
- _thread_run->interrupted = 0;
+ curthread->data.poll_data = &data;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_POLL_WAIT, __FILE__, __LINE__);
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
} else {
diff --git a/lib/libc_r/uthread/uthread_read.c b/lib/libc_r/uthread/uthread_read.c
index eb049a6cf57..b491ea99116 100644
--- a/lib/libc_r/uthread/uthread_read.c
+++ b/lib/libc_r/uthread/uthread_read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_read.c,v 1.6 2001/08/17 06:50:25 fgsch Exp $ */
+/* $OpenBSD: uthread_read.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.
@@ -45,6 +45,7 @@
ssize_t
read(int fd, void *buf, size_t nbytes)
{
+ struct pthread *curthread = _get_curthread();
ssize_t ret;
int type;
@@ -71,11 +72,11 @@ read(int fd, void *buf, size_t nbytes)
else while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) {
if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDR_WAIT,
__FILE__, __LINE__);
@@ -84,7 +85,7 @@ read(int fd, void *buf, size_t nbytes)
* Check if the operation was
* interrupted by a signal
*/
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libc_r/uthread/uthread_readv.c b/lib/libc_r/uthread/uthread_readv.c
index 4a91f7cb887..05661166b4c 100644
--- a/lib/libc_r/uthread/uthread_readv.c
+++ b/lib/libc_r/uthread/uthread_readv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_readv.c,v 1.4 2001/08/17 06:52:23 fgsch Exp $ */
+/* $OpenBSD: uthread_readv.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -45,6 +45,7 @@
ssize_t
readv(int fd, const struct iovec * iov, int iovcnt)
{
+ struct pthread *curthread = _get_curthread();
ssize_t ret;
int type;
@@ -65,11 +66,11 @@ readv(int fd, const struct iovec * iov, int iovcnt)
while ((ret = _thread_sys_readv(fd, iov, iovcnt)) < 0) {
if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDR_WAIT,
__FILE__, __LINE__);
@@ -78,7 +79,7 @@ readv(int fd, const struct iovec * iov, int iovcnt)
* Check if the operation was
* interrupted by a signal
*/
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libc_r/uthread/uthread_recvfrom.c b/lib/libc_r/uthread/uthread_recvfrom.c
index 18c0c6ce8ed..fee722f0b68 100644
--- a/lib/libc_r/uthread/uthread_recvfrom.c
+++ b/lib/libc_r/uthread/uthread_recvfrom.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_recvfrom.c,v 1.4 1999/11/25 07:01:42 d Exp $ */
+/* $OpenBSD: uthread_recvfrom.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,20 +43,21 @@
ssize_t
recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from, socklen_t *from_len)
{
+ struct pthread *curthread = _get_curthread();
int ret;
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;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
/* Check if the wait was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error status: */
errno = EINTR;
ret = -1;
diff --git a/lib/libc_r/uthread/uthread_recvmsg.c b/lib/libc_r/uthread/uthread_recvmsg.c
index c92b7a1c420..73fa874b123 100644
--- a/lib/libc_r/uthread/uthread_recvmsg.c
+++ b/lib/libc_r/uthread/uthread_recvmsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_recvmsg.c,v 1.3 1999/11/25 07:01:42 d Exp $ */
+/* $OpenBSD: uthread_recvmsg.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,20 +43,21 @@
ssize_t
recvmsg(int fd, struct msghdr *msg, int flags)
{
+ struct pthread *curthread = _get_curthread();
int ret;
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;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
/* Check if the wait was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error status: */
errno = EINTR;
ret = -1;
diff --git a/lib/libc_r/uthread/uthread_select.c b/lib/libc_r/uthread/uthread_select.c
index a7cd5c3d260..61708fa7c39 100644
--- a/lib/libc_r/uthread/uthread_select.c
+++ b/lib/libc_r/uthread/uthread_select.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_select.c,v 1.4 1999/11/25 07:01:42 d Exp $ */
+/* $OpenBSD: uthread_select.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -49,6 +49,7 @@ int
select(int numfds, fd_set * readfds, fd_set * writefds,
fd_set * exceptfds, struct timeval * timeout)
{
+ struct pthread *curthread = _get_curthread();
struct timespec ts;
int i, ret = 0, f_wait = 1;
int pfd_index, got_one = 0, fd_count = 0;
@@ -92,9 +93,9 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
* Allocate memory for poll data if it hasn't already been
* allocated or if previously allocated memory is insufficient.
*/
- if ((_thread_run->poll_data.fds == NULL) ||
- (_thread_run->poll_data.nfds < fd_count)) {
- data.fds = (struct pollfd *) realloc(_thread_run->poll_data.fds,
+ if ((curthread->poll_data.fds == NULL) ||
+ (curthread->poll_data.nfds < fd_count)) {
+ data.fds = (struct pollfd *) realloc(curthread->poll_data.fds,
sizeof(struct pollfd) * MAX(128, fd_count));
if (data.fds == NULL) {
errno = ENOMEM;
@@ -106,13 +107,13 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
* indicates what is allocated, not what is
* currently being polled.
*/
- _thread_run->poll_data.fds = data.fds;
- _thread_run->poll_data.nfds = MAX(128, fd_count);
+ curthread->poll_data.fds = data.fds;
+ curthread->poll_data.nfds = MAX(128, fd_count);
}
}
if (ret == 0) {
/* Setup the wait data. */
- data.fds = _thread_run->poll_data.fds;
+ data.fds = curthread->poll_data.fds;
data.nfds = fd_count;
/*
@@ -145,10 +146,10 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
}
if (((ret = _thread_sys_poll(data.fds, data.nfds, 0)) == 0) &&
(f_wait != 0)) {
- _thread_run->data.poll_data = &data;
- _thread_run->interrupted = 0;
+ curthread->data.poll_data = &data;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_SELECT_WAIT, __FILE__, __LINE__);
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
data.nfds = 0;
ret = -1;
diff --git a/lib/libc_r/uthread/uthread_self.c b/lib/libc_r/uthread/uthread_self.c
index 0ff4f7f3ba6..5c0c53c4cbc 100644
--- a/lib/libc_r/uthread/uthread_self.c
+++ b/lib/libc_r/uthread/uthread_self.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_self.c,v 1.3 1999/11/25 07:01:43 d Exp $ */
+/* $OpenBSD: uthread_self.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -40,6 +40,6 @@ pthread_t
pthread_self(void)
{
/* Return the running thread pointer: */
- return (_thread_run);
+ return (_get_curthread());
}
#endif
diff --git a/lib/libc_r/uthread/uthread_sendmsg.c b/lib/libc_r/uthread/uthread_sendmsg.c
index 36bc6a62439..11d91d85c5c 100644
--- a/lib/libc_r/uthread/uthread_sendmsg.c
+++ b/lib/libc_r/uthread/uthread_sendmsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sendmsg.c,v 1.3 1999/11/25 07:01:43 d Exp $ */
+/* $OpenBSD: uthread_sendmsg.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,20 +43,21 @@
ssize_t
sendmsg(int fd, const struct msghdr *msg, int flags)
{
+ struct pthread *curthread = _get_curthread();
int ret;
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;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__);
/* Check if the operation was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libc_r/uthread/uthread_sendto.c b/lib/libc_r/uthread/uthread_sendto.c
index b0a8c059a1e..062d11e77ac 100644
--- a/lib/libc_r/uthread/uthread_sendto.c
+++ b/lib/libc_r/uthread/uthread_sendto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sendto.c,v 1.4 1999/11/25 07:01:43 d Exp $ */
+/* $OpenBSD: uthread_sendto.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,20 +43,21 @@
ssize_t
sendto(int fd, const void *msg, size_t len, int flags, const struct sockaddr * to, socklen_t to_len)
{
+ struct pthread *curthread = _get_curthread();
int ret;
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;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__);
/* Check if the operation was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libc_r/uthread/uthread_sig.c b/lib/libc_r/uthread/uthread_sig.c
index 1cdbc362aa6..56aea46c28f 100644
--- a/lib/libc_r/uthread/uthread_sig.c
+++ b/lib/libc_r/uthread/uthread_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sig.c,v 1.7 2000/01/06 07:20:52 d Exp $ */
+/* $OpenBSD: uthread_sig.c,v 1.8 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -65,6 +65,7 @@ _thread_sig_init(void)
void
_thread_sig_handler(int sig, int code, struct sigcontext * scp)
{
+ struct pthread *curthread = _get_curthread();
char c;
int i;
@@ -81,8 +82,8 @@ _thread_sig_handler(int sig, int code, struct sigcontext * scp)
* the currently running thread has deferred thread
* signals.
*/
- else if (_thread_run->sig_defer_count > 0)
- _thread_run->yield_on_sig_undefer = 1;
+ else if (curthread->sig_defer_count > 0)
+ curthread->yield_on_sig_undefer = 1;
else {
/*
@@ -105,7 +106,7 @@ _thread_sig_handler(int sig, int code, struct sigcontext * scp)
* running thread that has deferred signals.
*/
else if ((_queue_signals != 0) || ((_thread_kern_in_sched == 0) &&
- (_thread_run->sig_defer_count > 0))) {
+ (curthread->sig_defer_count > 0))) {
/* Cast the signal number to a character variable: */
c = sig;
@@ -151,6 +152,7 @@ _thread_sig_handler(int sig, int code, struct sigcontext * scp)
void
_thread_sig_handle(int sig, struct sigcontext * scp)
{
+ struct pthread *curthread = _get_curthread();
int i;
pthread_t pthread, pthread_next;
@@ -238,13 +240,13 @@ _thread_sig_handle(int sig, struct sigcontext * scp)
* list:
*/
TAILQ_FOREACH(pthread, &_thread_list, tle) {
- pthread_t pthread_saved = _thread_run;
+ pthread_t pthread_saved = curthread;
/* Current thread inside critical region? */
- if (_thread_run->sig_defer_count > 0)
+ if (curthread->sig_defer_count > 0)
pthread->sig_defer_count++;
- _thread_run = pthread;
+ curthread = pthread;
_thread_signal(pthread,sig);
/*
@@ -252,10 +254,10 @@ _thread_sig_handle(int sig, struct sigcontext * scp)
* running thread:
*/
_dispatch_signals();
- _thread_run = pthread_saved;
+ curthread = pthread_saved;
/* Current thread inside critical region? */
- if (_thread_run->sig_defer_count > 0)
+ if (curthread->sig_defer_count > 0)
pthread->sig_defer_count--;
}
}
@@ -362,13 +364,14 @@ _thread_signal(pthread_t pthread, int sig)
void
_dispatch_signals()
{
+ struct pthread *curthread = _get_curthread();
int i;
/*
* Check if there are pending signals for the running
* thread that aren't blocked:
*/
- if ((_thread_run->sigpend & ~_thread_run->sigmask) != 0)
+ if ((curthread->sigpend & ~curthread->sigmask) != 0)
/* Look for all possible pending signals: */
for (i = 1; i < NSIG; i++)
/*
@@ -377,10 +380,10 @@ _dispatch_signals()
*/
if (_thread_sigact[i - 1].sa_handler != SIG_DFL &&
_thread_sigact[i - 1].sa_handler != SIG_IGN &&
- sigismember(&_thread_run->sigpend,i) &&
- !sigismember(&_thread_run->sigmask,i)) {
+ sigismember(&curthread->sigpend,i) &&
+ !sigismember(&curthread->sigmask,i)) {
/* Clear the pending signal: */
- sigdelset(&_thread_run->sigpend,i);
+ sigdelset(&curthread->sigpend,i);
/*
* Dispatch the signal via the custom signal
diff --git a/lib/libc_r/uthread/uthread_sigmask.c b/lib/libc_r/uthread/uthread_sigmask.c
index 6de570535e4..03fb4963395 100644
--- a/lib/libc_r/uthread/uthread_sigmask.c
+++ b/lib/libc_r/uthread/uthread_sigmask.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sigmask.c,v 1.3 1999/11/25 07:01:44 d Exp $ */
+/* $OpenBSD: uthread_sigmask.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -41,12 +41,13 @@
int
pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
/* Check if the existing signal process mask is to be returned: */
if (oset != NULL) {
/* Return the current mask: */
- *oset = _thread_run->sigmask;
+ *oset = curthread->sigmask;
}
/* Check if a new signal set was provided by the caller: */
if (set != NULL) {
@@ -55,19 +56,19 @@ pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
/* Block signals: */
case SIG_BLOCK:
/* Add signals to the existing mask: */
- _thread_run->sigmask |= *set;
+ curthread->sigmask |= *set;
break;
/* Unblock signals: */
case SIG_UNBLOCK:
/* Clear signals from the existing mask: */
- _thread_run->sigmask &= ~(*set);
+ curthread->sigmask &= ~(*set);
break;
/* Set the signal process mask: */
case SIG_SETMASK:
/* Set the new mask: */
- _thread_run->sigmask = *set;
+ curthread->sigmask = *set;
break;
/* Trap invalid actions: */
diff --git a/lib/libc_r/uthread/uthread_sigpending.c b/lib/libc_r/uthread/uthread_sigpending.c
index 9921ee5a237..911d1b4b891 100644
--- a/lib/libc_r/uthread/uthread_sigpending.c
+++ b/lib/libc_r/uthread/uthread_sigpending.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sigpending.c,v 1.2 1999/11/25 07:01:45 d Exp $ */
+/* $OpenBSD: uthread_sigpending.c,v 1.3 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1999 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
@@ -41,6 +41,7 @@
int
sigpending(sigset_t * set)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
/* Check for a null signal set pointer: */
@@ -49,7 +50,7 @@ sigpending(sigset_t * set)
ret = EINVAL;
}
else {
- *set = _thread_run->sigpend;
+ *set = curthread->sigpend;
}
/* Return the completion status: */
return (ret);
diff --git a/lib/libc_r/uthread/uthread_sigsuspend.c b/lib/libc_r/uthread/uthread_sigsuspend.c
index bd7e2094bd9..bbf9c7c9870 100644
--- a/lib/libc_r/uthread/uthread_sigsuspend.c
+++ b/lib/libc_r/uthread/uthread_sigsuspend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sigsuspend.c,v 1.4 1999/11/25 07:01:45 d Exp $ */
+/* $OpenBSD: uthread_sigsuspend.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -41,16 +41,19 @@
int
sigsuspend(const sigset_t * set)
{
+ struct pthread *curthread = _get_curthread();
int ret = -1;
sigset_t oset;
+ _thread_enter_cancellation_point();
+
/* Check if a new signal set was provided by the caller: */
if (set != NULL) {
/* Save the current signal mask: */
- oset = _thread_run->sigmask;
+ oset = curthread->sigmask;
/* Change the caller's mask: */
- _thread_run->sigmask = *set;
+ curthread->sigmask = *set;
/* Wait for a signal: */
_thread_kern_sched_state(PS_SIGSUSPEND, __FILE__, __LINE__);
@@ -59,12 +62,14 @@ sigsuspend(const sigset_t * set)
errno = EINTR;
/* Restore the signal mask: */
- _thread_run->sigmask = oset;
+ curthread->sigmask = oset;
} else {
/* Return an invalid argument error: */
errno = EINVAL;
}
+ _thread_leave_cancellation_point();
+
/* Return the completion status: */
return (ret);
}
diff --git a/lib/libc_r/uthread/uthread_sigwait.c b/lib/libc_r/uthread/uthread_sigwait.c
index abcc1d6e894..1ae76ab1926 100644
--- a/lib/libc_r/uthread/uthread_sigwait.c
+++ b/lib/libc_r/uthread/uthread_sigwait.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sigwait.c,v 1.8 2000/01/06 07:21:14 d Exp $ */
+/* $OpenBSD: uthread_sigwait.c,v 1.9 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -41,6 +41,7 @@
int
sigwait(const sigset_t * set, int *sig)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
int i;
sigset_t tempset, waitset;
@@ -72,7 +73,7 @@ sigwait(const sigset_t * set, int *sig)
sigdelset(&waitset, SIGINFO);
/* Check to see if a pending signal is in the wait mask. */
- if ((tempset = (_thread_run->sigpend & waitset)) != 0) {
+ if ((tempset = (curthread->sigpend & waitset)) != 0) {
/* Enter a loop to find a pending signal: */
for (i = 1; i < NSIG; i++) {
if (sigismember (&tempset, i))
@@ -80,7 +81,7 @@ sigwait(const sigset_t * set, int *sig)
}
/* Clear the pending signal: */
- sigdelset(&_thread_run->sigpend,i);
+ sigdelset(&curthread->sigpend,i);
/* Return the signal number to the caller: */
*sig = i;
@@ -115,19 +116,19 @@ sigwait(const sigset_t * set, int *sig)
* mask is independent of the threads signal mask
* and requires separate storage.
*/
- _thread_run->data.sigwait = &waitset;
+ curthread->data.sigwait = &waitset;
/* Wait for a signal: */
_thread_kern_sched_state(PS_SIGWAIT, __FILE__, __LINE__);
/* Return the signal number to the caller: */
- *sig = _thread_run->signo;
+ *sig = curthread->signo;
/*
* Probably unnecessary, but since it's in a union struct
* we don't know how it could be used in the future.
*/
- _thread_run->data.sigwait = NULL;
+ curthread->data.sigwait = NULL;
}
/* Restore the sigactions: */
diff --git a/lib/libc_r/uthread/uthread_single_np.c b/lib/libc_r/uthread/uthread_single_np.c
index 84208893b16..a1820b311bc 100644
--- a/lib/libc_r/uthread/uthread_single_np.c
+++ b/lib/libc_r/uthread/uthread_single_np.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_single_np.c,v 1.3 1999/11/25 07:01:45 d Exp $ */
+/* $OpenBSD: uthread_single_np.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -39,8 +39,10 @@
int pthread_single_np()
{
+ struct pthread *curthread = _get_curthread();
+
/* Enter single-threaded (non-POSIX) scheduling mode: */
- _thread_single = _thread_run;
+ _thread_single = curthread;
return(0);
}
#endif
diff --git a/lib/libc_r/uthread/uthread_spec.c b/lib/libc_r/uthread/uthread_spec.c
index 1ac1df46fe4..b1fdeb9dfa5 100644
--- a/lib/libc_r/uthread/uthread_spec.c
+++ b/lib/libc_r/uthread/uthread_spec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_spec.c,v 1.6 1999/11/25 07:01:46 d Exp $ */
+/* $OpenBSD: uthread_spec.c,v 1.7 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -89,6 +89,7 @@ pthread_key_delete(pthread_key_t key)
void
_thread_cleanupspecific(void)
{
+ struct pthread *curthread = _get_curthread();
void *data;
int key;
int itr;
@@ -96,16 +97,16 @@ _thread_cleanupspecific(void)
for (itr = 0; itr < PTHREAD_DESTRUCTOR_ITERATIONS; itr++) {
for (key = 0; key < PTHREAD_KEYS_MAX; key++) {
- if (_thread_run->specific_data_count) {
+ if (curthread->specific_data_count) {
/* Lock the key table entry: */
_SPINLOCK(&key_table[key].lock);
destructor = data = 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 (curthread->specific_data[key]) {
+ data = (void *) curthread->specific_data[key];
+ curthread->specific_data[key] = NULL;
+ curthread->specific_data_count--;
destructor = key_table[key].destructor;
}
}
@@ -120,14 +121,14 @@ _thread_cleanupspecific(void)
if (destructor)
destructor(data);
} else {
- free(_thread_run->specific_data);
- _thread_run->specific_data = NULL;
+ free(curthread->specific_data);
+ curthread->specific_data = NULL;
return;
}
}
}
- free(_thread_run->specific_data);
- _thread_run->specific_data = NULL;
+ free(curthread->specific_data);
+ curthread->specific_data = NULL;
}
static inline const void **
@@ -143,11 +144,11 @@ pthread_key_allocate_data(void)
int
pthread_setspecific(pthread_key_t key, const void *value)
{
- pthread_t pthread;
- int ret = 0;
+ struct pthread *pthread;
+ int ret = 0;
/* Point to the running thread: */
- pthread = _thread_run;
+ pthread = _get_curthread();
if ((pthread->specific_data) ||
(pthread->specific_data = pthread_key_allocate_data())) {
@@ -174,11 +175,11 @@ pthread_setspecific(pthread_key_t key, const void *value)
void *
pthread_getspecific(pthread_key_t key)
{
- pthread_t pthread;
+ struct pthread *pthread;
void *data;
/* Point to the running thread: */
- pthread = _thread_run;
+ pthread = _get_curthread();
/* Check if there is specific data: */
if (pthread->specific_data != NULL && key < PTHREAD_KEYS_MAX) {
diff --git a/lib/libc_r/uthread/uthread_spinlock.c b/lib/libc_r/uthread/uthread_spinlock.c
index 41381e18321..418ddcf3427 100644
--- a/lib/libc_r/uthread/uthread_spinlock.c
+++ b/lib/libc_r/uthread/uthread_spinlock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_spinlock.c,v 1.7 2000/01/06 07:22:04 d Exp $ */
+/* $OpenBSD: uthread_spinlock.c,v 1.8 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -52,18 +52,20 @@ extern char *__progname;
void
_spinlock(spinlock_t *lck)
{
+ struct pthread *curthread = _get_curthread();
+
/*
* Try to grab the lock and loop if another thread grabs
* it before we do.
*/
while(_atomic_lock(&lck->access_lock)) {
/* Block the thread until the lock. */
- _thread_run->data.spinlock = lck;
+ curthread->data.spinlock = lck;
_thread_kern_sched_state(PS_SPINBLOCK, __FILE__, __LINE__);
}
/* The running thread now owns the lock: */
- lck->lock_owner = _thread_run;
+ lck->lock_owner = curthread;
}
/*
@@ -79,6 +81,7 @@ _spinlock(spinlock_t *lck)
void
_spinlock_debug(spinlock_t *lck, const char *fname, int lineno)
{
+ struct pthread *curthread = _get_curthread();
int cnt = 0;
/*
@@ -89,19 +92,19 @@ _spinlock_debug(spinlock_t *lck, const char *fname, int lineno)
cnt++;
if (cnt > 100) {
char str[256];
- snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, _thread_run, lck, fname, lineno, lck->fname, lck->lineno);
+ snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno);
_thread_sys_write(2,str,strlen(str));
sleep(1);
cnt = 0;
}
/* Block the thread until the lock. */
- _thread_run->data.spinlock = lck;
+ curthread->data.spinlock = lck;
_thread_kern_sched_state(PS_SPINBLOCK, fname, lineno);
}
/* The running thread now owns the lock: */
- lck->lock_owner = _thread_run;
+ lck->lock_owner = curthread;
lck->fname = fname;
lck->lineno = lineno;
}
diff --git a/lib/libc_r/uthread/uthread_wait4.c b/lib/libc_r/uthread/uthread_wait4.c
index 0c3efa803f2..b51d6b29d6c 100644
--- a/lib/libc_r/uthread/uthread_wait4.c
+++ b/lib/libc_r/uthread/uthread_wait4.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_wait4.c,v 1.5 1999/11/25 07:01:47 d Exp $ */
+/* $OpenBSD: uthread_wait4.c,v 1.6 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -41,6 +41,7 @@
pid_t
wait4(pid_t pid, int *istat, int options, struct rusage * rusage)
{
+ struct pthread *curthread = _get_curthread();
pid_t ret;
/* This is a cancellation point: */
@@ -51,13 +52,13 @@ wait4(pid_t pid, int *istat, int options, struct rusage * rusage)
/* Perform a non-blocking wait4 syscall: */
while ((ret = _thread_sys_wait4(pid, istat, options | WNOHANG, rusage)) == 0 && (options & WNOHANG) == 0) {
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
/* Schedule the next thread while this one waits: */
_thread_kern_sched_state(PS_WAIT_WAIT, __FILE__, __LINE__);
/* Check if this call was interrupted by a signal: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libc_r/uthread/uthread_write.c b/lib/libc_r/uthread/uthread_write.c
index 05c83bbcd22..09cd9001055 100644
--- a/lib/libc_r/uthread/uthread_write.c
+++ b/lib/libc_r/uthread/uthread_write.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_write.c,v 1.7 2001/08/11 15:01:57 fgsch Exp $ */
+/* $OpenBSD: uthread_write.c,v 1.8 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -45,6 +45,7 @@
ssize_t
write(int fd, const void *buf, size_t nbytes)
{
+ struct pthread *curthread = _get_curthread();
int blocking;
int type;
ssize_t n;
@@ -99,11 +100,11 @@ write(int fd, const void *buf, size_t nbytes)
*/
if (blocking && ((n < 0 && (errno == EWOULDBLOCK ||
errno == EAGAIN)) || (n >= 0 && num < nbytes))) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDW_WAIT,
__FILE__, __LINE__);
@@ -112,7 +113,7 @@ write(int fd, const void *buf, size_t nbytes)
* Check if the operation was
* interrupted by a signal
*/
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error: */
ret = -1;
}
diff --git a/lib/libc_r/uthread/uthread_writev.c b/lib/libc_r/uthread/uthread_writev.c
index be26356d2c9..eb5d6418a98 100644
--- a/lib/libc_r/uthread/uthread_writev.c
+++ b/lib/libc_r/uthread/uthread_writev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_writev.c,v 1.4 2001/08/11 14:56:07 fgsch Exp $ */
+/* $OpenBSD: uthread_writev.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -47,6 +47,7 @@
ssize_t
writev(int fd, const struct iovec * iov, int iovcnt)
{
+ struct pthread *curthread = _get_curthread();
int blocking;
int idx = 0;
int type;
@@ -159,11 +160,11 @@ writev(int fd, const struct iovec * iov, int iovcnt)
*/
if (blocking && ((n < 0 && (errno == EWOULDBLOCK ||
errno == EAGAIN)) || (n >= 0 && idx < iovcnt))) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDW_WAIT,
__FILE__, __LINE__);
@@ -172,7 +173,7 @@ writev(int fd, const struct iovec * iov, int iovcnt)
* Check if the operation was
* interrupted by a signal
*/
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error: */
ret = -1;
}
diff --git a/lib/libc_r/uthread/uthread_yield.c b/lib/libc_r/uthread/uthread_yield.c
index 055555dec6d..32852ee847a 100644
--- a/lib/libc_r/uthread/uthread_yield.c
+++ b/lib/libc_r/uthread/uthread_yield.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_yield.c,v 1.4 2001/08/04 14:43:53 fgsch Exp $ */
+/* $OpenBSD: uthread_yield.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -39,8 +39,10 @@
int
sched_yield(void)
{
+ struct pthread *curthread = _get_curthread();
+
/* Reset the accumulated time slice value for the current thread: */
- _thread_run->slice_usec = -1;
+ curthread->slice_usec = -1;
/* Schedule the next thread: */
_thread_kern_sched(NULL);
@@ -53,8 +55,10 @@ sched_yield(void)
void
pthread_yield(void)
{
+ struct pthread *curthread = _get_curthread();
+
/* Reset the accumulated time slice value for the current thread: */
- _thread_run->slice_usec = -1;
+ curthread->slice_usec = -1;
/* Schedule the next thread: */
_thread_kern_sched(NULL);
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h
index cff1cba3e90..71b013db60e 100644
--- a/lib/libpthread/uthread/pthread_private.h
+++ b/lib/libpthread/uthread/pthread_private.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pthread_private.h,v 1.22 2001/08/15 23:50:34 fgsch Exp $ */
+/* $OpenBSD: pthread_private.h,v 1.23 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -278,7 +278,7 @@ struct pthread_mutex_attr {
*/
enum pthread_cond_type {
COND_TYPE_FAST,
-#define COND_TYPE_MAX ((int)COND_TYPE_FAST + 1)
+ COND_TYPE_MAX
};
struct pthread_cond {
@@ -287,6 +287,7 @@ struct pthread_cond {
pthread_mutex_t c_mutex;
void *c_data;
long c_flags;
+ int c_seqno;
/*
* Lock for accesses to this structure.
@@ -333,6 +334,7 @@ struct pthread_attr {
void (*cleanup_attr) ();
void *stackaddr_attr;
size_t stacksize_attr;
+ size_t guardsize_attr;
};
/*
@@ -409,8 +411,8 @@ enum pthread_state {
PS_JOIN,
PS_SUSPENDED,
PS_DEAD,
- PS_DEADLOCK
-#define PS_STATE_MAX ((int)PS_DEADLOCK + 1)
+ PS_DEADLOCK,
+ PS_STATE_MAX
};
@@ -803,6 +805,8 @@ extern int _thread_kern_new_state;
__BEGIN_DECLS
int _find_dead_thread(pthread_t);
int _find_thread(pthread_t);
+struct pthread *_get_curthread(void);
+void _set_curthread(struct pthread *);
int _thread_create(pthread_t *,const pthread_attr_t *,void *(*start_routine)(void *),void *,pthread_t);
void _dispatch_signals(void);
void _thread_signal(pthread_t, int);
diff --git a/lib/libpthread/uthread/uthread_accept.c b/lib/libpthread/uthread/uthread_accept.c
index db8d078c444..23197f8dadc 100644
--- a/lib/libpthread/uthread/uthread_accept.c
+++ b/lib/libpthread/uthread/uthread_accept.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_accept.c,v 1.4 1999/11/25 07:01:30 d Exp $ */
+/* $OpenBSD: uthread_accept.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -44,6 +44,7 @@
int
accept(int fd, struct sockaddr * name, socklen_t *namelen)
{
+ struct pthread *curthread = _get_curthread();
int ret;
/* Lock the file descriptor: */
@@ -53,19 +54,19 @@ accept(int fd, struct sockaddr * name, socklen_t *namelen)
/* Check if the socket is to block: */
if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && (errno == EWOULDBLOCK || errno == EAGAIN)) {
/* Save the socket file descriptor: */
- _thread_run->data.fd.fd = fd;
- _thread_run->data.fd.fname = __FILE__;
- _thread_run->data.fd.branch = __LINE__;
+ curthread->data.fd.fd = fd;
+ curthread->data.fd.fname = __FILE__;
+ curthread->data.fd.branch = __LINE__;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
/* Schedule the next thread: */
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
/* Check if the wait was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error status: */
errno = EINTR;
ret = -1;
diff --git a/lib/libpthread/uthread/uthread_cancel.c b/lib/libpthread/uthread/uthread_cancel.c
index e43e03bf00b..7428ee07ecb 100644
--- a/lib/libpthread/uthread/uthread_cancel.c
+++ b/lib/libpthread/uthread/uthread_cancel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_cancel.c,v 1.2 1999/11/25 07:01:32 d Exp $ */
+/* $OpenBSD: uthread_cancel.c,v 1.3 2001/08/21 19:24:53 fgsch Exp $ */
/*
* David Leonard <d@openbsd.org>, 1999. Public domain.
*/
@@ -64,24 +64,25 @@ pthread_setcancelstate(state, oldstate)
int state;
int *oldstate;
{
+ struct pthread *curthread = _get_curthread();
int ostate;
int ret;
- ostate = _thread_run->cancelstate;
+ ostate = curthread->cancelstate;
switch (state) {
case PTHREAD_CANCEL_ENABLE:
if (oldstate)
*oldstate = ostate;
- _thread_run->cancelstate = PTHREAD_CANCEL_ENABLE;
- if (_thread_run->canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)
+ curthread->cancelstate = PTHREAD_CANCEL_ENABLE;
+ if (curthread->canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)
_thread_cancellation_point();
ret = 0;
break;
case PTHREAD_CANCEL_DISABLE:
if (oldstate)
*oldstate = ostate;
- _thread_run->cancelstate = PTHREAD_CANCEL_DISABLE;
+ curthread->cancelstate = PTHREAD_CANCEL_DISABLE;
ret = 0;
break;
default:
@@ -97,22 +98,23 @@ pthread_setcanceltype(type, oldtype)
int type;
int *oldtype;
{
+ struct pthread *curthread = _get_curthread();
int otype;
int ret;
- otype = _thread_run->canceltype;
+ otype = curthread->canceltype;
switch (type) {
case PTHREAD_CANCEL_ASYNCHRONOUS:
if (oldtype)
*oldtype = otype;
- _thread_run->canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
+ curthread->canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
_thread_cancellation_point();
ret = 0;
break;
case PTHREAD_CANCEL_DEFERRED:
if (oldtype)
*oldtype = otype;
- _thread_run->canceltype = PTHREAD_CANCEL_DEFERRED;
+ curthread->canceltype = PTHREAD_CANCEL_DEFERRED;
ret = 0;
break;
default:
@@ -132,17 +134,19 @@ pthread_testcancel()
void
_thread_enter_cancellation_point()
{
+ struct pthread *curthread = _get_curthread();
/* Look for a cancellation before we block: */
_thread_cancellation_point();
- _thread_run->flags |= PTHREAD_FLAGS_CANCELPT;
+ curthread->flags |= PTHREAD_FLAGS_CANCELPT;
}
void
_thread_leave_cancellation_point()
{
+ struct pthread *curthread = _get_curthread();
- _thread_run->flags &=~ PTHREAD_FLAGS_CANCELPT;
+ curthread->flags &=~ PTHREAD_FLAGS_CANCELPT;
/* Look for a cancellation after we unblock: */
_thread_cancellation_point();
}
@@ -154,11 +158,12 @@ _thread_leave_cancellation_point()
void
_thread_cancellation_point()
{
+ struct pthread *curthread = _get_curthread();
- if ((_thread_run->cancelstate == PTHREAD_CANCEL_ENABLE) &&
- ((_thread_run->flags & (PTHREAD_FLAGS_CANCELED|PTHREAD_EXITING)) ==
+ if ((curthread->cancelstate == PTHREAD_CANCEL_ENABLE) &&
+ ((curthread->flags & (PTHREAD_FLAGS_CANCELED|PTHREAD_EXITING)) ==
PTHREAD_FLAGS_CANCELED)) {
- _thread_run->flags &=~ PTHREAD_FLAGS_CANCELED;
+ curthread->flags &=~ PTHREAD_FLAGS_CANCELED;
pthread_exit(PTHREAD_CANCELED);
PANIC("cancel");
}
diff --git a/lib/libpthread/uthread/uthread_clean.c b/lib/libpthread/uthread/uthread_clean.c
index 0fc9a272f7f..ed6df7d70b6 100644
--- a/lib/libpthread/uthread/uthread_clean.c
+++ b/lib/libpthread/uthread/uthread_clean.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_clean.c,v 1.3 1999/11/25 07:01:32 d Exp $ */
+/* $OpenBSD: uthread_clean.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -42,24 +42,26 @@
void
pthread_cleanup_push(void (*routine) (void *), void *routine_arg)
{
+ struct pthread *curthread = _get_curthread();
struct pthread_cleanup *new;
if ((new = (struct pthread_cleanup *) malloc(sizeof(struct pthread_cleanup))) != NULL) {
new->routine = routine;
new->routine_arg = routine_arg;
- new->next = _thread_run->cleanup;
+ new->next = curthread->cleanup;
- _thread_run->cleanup = new;
+ curthread->cleanup = new;
}
}
void
pthread_cleanup_pop(int execute)
{
+ struct pthread *curthread = _get_curthread();
struct pthread_cleanup *old;
- if ((old = _thread_run->cleanup) != NULL) {
- _thread_run->cleanup = old->next;
+ if ((old = curthread->cleanup) != NULL) {
+ curthread->cleanup = old->next;
if (execute) {
old->routine(old->routine_arg);
}
diff --git a/lib/libpthread/uthread/uthread_cond.c b/lib/libpthread/uthread/uthread_cond.c
index 1991bb472c8..48ee72a6b2f 100644
--- a/lib/libpthread/uthread/uthread_cond.c
+++ b/lib/libpthread/uthread/uthread_cond.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_cond.c,v 1.9 2000/01/06 07:14:47 d Exp $ */
+/* $OpenBSD: uthread_cond.c,v 1.10 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -158,6 +158,7 @@ pthread_cond_destroy(pthread_cond_t * cond)
int
pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
{
+ struct pthread *curthread = _get_curthread();
int rval = 0;
/* This is a cancellation point: */
@@ -197,19 +198,19 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
rval = EINVAL;
} else {
/* Reset the timeout flag: */
- _thread_run->timeout = 0;
+ curthread->timeout = 0;
/*
* Queue the running thread for the condition
* variable:
*/
- cond_queue_enq(*cond, _thread_run);
+ cond_queue_enq(*cond, curthread);
/* Remember the mutex that is being used: */
(*cond)->c_mutex = *mutex;
/* Wait forever: */
- _thread_run->wakeup_time.tv_sec = -1;
+ curthread->wakeup_time.tv_sec = -1;
/* Unlock the mutex: */
if ((rval = _mutex_cv_unlock(mutex)) != 0) {
@@ -218,7 +219,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
* the running thread from the condition
* variable queue:
*/
- cond_queue_remove(*cond, _thread_run);
+ cond_queue_remove(*cond, curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) ==
@@ -264,6 +265,7 @@ int
pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
const struct timespec * abstime)
{
+ struct pthread *curthread = _get_curthread();
int rval = 0;
/* This is a cancellation point: */
@@ -307,19 +309,19 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
_SPINUNLOCK(&(*cond)->lock);
} else {
/* Set the wakeup time: */
- _thread_run->wakeup_time.tv_sec =
+ curthread->wakeup_time.tv_sec =
abstime->tv_sec;
- _thread_run->wakeup_time.tv_nsec =
+ curthread->wakeup_time.tv_nsec =
abstime->tv_nsec;
/* Reset the timeout flag: */
- _thread_run->timeout = 0;
+ curthread->timeout = 0;
/*
* Queue the running thread for the condition
* variable:
*/
- cond_queue_enq(*cond, _thread_run);
+ cond_queue_enq(*cond, curthread);
/* Remember the mutex that is being used: */
(*cond)->c_mutex = *mutex;
@@ -331,7 +333,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
* the running thread from the condition
* variable queue:
*/
- cond_queue_remove(*cond, _thread_run);
+ cond_queue_remove(*cond, curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
@@ -348,7 +350,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
&(*cond)->lock, __FILE__, __LINE__);
/* Check if the wait timedout: */
- if (_thread_run->timeout == 0) {
+ if (curthread->timeout == 0) {
/* Lock the mutex: */
rval = _mutex_cv_lock(mutex);
}
@@ -362,7 +364,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
* variable queue:
*/
cond_queue_remove(*cond,
- _thread_run);
+ curthread);
/* Check for no more waiters: */
if (TAILQ_FIRST(&(*cond)->c_queue) == NULL)
diff --git a/lib/libpthread/uthread/uthread_connect.c b/lib/libpthread/uthread/uthread_connect.c
index a6a2f367189..ad0a6ea8921 100644
--- a/lib/libpthread/uthread/uthread_connect.c
+++ b/lib/libpthread/uthread/uthread_connect.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_connect.c,v 1.3 1999/11/25 07:01:33 d Exp $ */
+/* $OpenBSD: uthread_connect.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,6 +43,7 @@
int
connect(int fd, const struct sockaddr * name, socklen_t namelen)
{
+ struct pthread *curthread = _get_curthread();
struct sockaddr tmpname;
int errnolen, ret, tmpnamelen;
@@ -51,7 +52,7 @@ connect(int fd, const struct sockaddr * name, socklen_t namelen)
if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) &&
((errno == EWOULDBLOCK) || (errno == EINPROGRESS) ||
(errno == EALREADY) || (errno == EAGAIN))) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
diff --git a/lib/libpthread/uthread/uthread_create.c b/lib/libpthread/uthread/uthread_create.c
index a1981e90f3c..82606872c1d 100644
--- a/lib/libpthread/uthread/uthread_create.c
+++ b/lib/libpthread/uthread/uthread_create.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_create.c,v 1.14 2000/10/04 05:55:35 d Exp $ */
+/* $OpenBSD: uthread_create.c,v 1.15 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -49,6 +49,7 @@ int
pthread_create(pthread_t * thread, const pthread_attr_t * attr,
void *(*start_routine) (void *), void *arg)
{
+ struct pthread *curthread = _get_curthread();
int f_gc = 0;
int ret = 0;
pthread_t gc_thread;
@@ -102,7 +103,7 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
new_thread->magic = PTHREAD_MAGIC;
/* Initialise the thread for signals: */
- new_thread->sigmask = _thread_run->sigmask;
+ new_thread->sigmask = curthread->sigmask;
/*
* Set up new stack frame so that it 'returns' to
@@ -122,11 +123,11 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
if (new_thread->attr.flags & PTHREAD_INHERIT_SCHED) {
/* Copy the scheduling attributes: */
new_thread->base_priority
- = _thread_run->base_priority;
+ = curthread->base_priority;
new_thread->attr.prio
- = _thread_run->base_priority;
+ = curthread->base_priority;
new_thread->attr.sched_policy
- = _thread_run->attr.sched_policy;
+ = curthread->attr.sched_policy;
} else {
/*
* Use just the thread priority, leaving the
@@ -205,11 +206,13 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
void
_thread_start(void)
{
+ struct pthread *curthread = _get_curthread();
+
/* We just left the scheduler via longjmp: */
_thread_kern_in_sched = 0;
/* Run the current thread's start routine with argument: */
- pthread_exit(_thread_run->start_routine(_thread_run->arg));
+ pthread_exit(curthread->start_routine(curthread->arg));
/* This point should never be reached. */
PANIC("Thread has resumed after exit");
diff --git a/lib/libpthread/uthread/uthread_execve.c b/lib/libpthread/uthread/uthread_execve.c
index b401dd1a145..d6b9c8116b5 100644
--- a/lib/libpthread/uthread/uthread_execve.c
+++ b/lib/libpthread/uthread/uthread_execve.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_execve.c,v 1.5 1999/11/25 07:01:34 d Exp $ */
+/* $OpenBSD: uthread_execve.c,v 1.6 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -42,6 +42,7 @@
int
execve(const char *name, char *const * argv, char *const * envp)
{
+ struct pthread *curthread = _get_curthread();
int flags;
int i;
int ret;
@@ -103,7 +104,7 @@ execve(const char *name, char *const * argv, char *const * envp)
}
/* Set the signal mask: */
- _thread_sys_sigprocmask(SIG_SETMASK, &_thread_run->sigmask, NULL);
+ _thread_sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
/* Execute the process: */
ret = _thread_sys_execve(name, argv, envp);
diff --git a/lib/libpthread/uthread/uthread_exit.c b/lib/libpthread/uthread/uthread_exit.c
index 8e884f70727..c6013cbf1ea 100644
--- a/lib/libpthread/uthread/uthread_exit.c
+++ b/lib/libpthread/uthread/uthread_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_exit.c,v 1.12 2000/01/06 07:16:40 d Exp $ */
+/* $OpenBSD: uthread_exit.c,v 1.13 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -145,29 +145,30 @@ _thread_exit(const char *fname, int lineno, const char *string)
void
pthread_exit(void *status)
{
+ struct pthread *curthread = _get_curthread();
pthread_t pthread;
/* Check if this thread is already in the process of exiting: */
- if ((_thread_run->flags & PTHREAD_EXITING) != 0) {
+ if ((curthread->flags & PTHREAD_EXITING) != 0) {
PANIC("Thread has called pthread_exit() from a destructor. POSIX 1003.1 1996 s16.2.5.2 does not allow this!");
}
/* Flag this thread as exiting: */
- _thread_run->flags |= PTHREAD_EXITING;
+ curthread->flags |= PTHREAD_EXITING;
/* Save the return value: */
- _thread_run->ret = status;
+ curthread->ret = status;
- while (_thread_run->cleanup != NULL) {
+ while (curthread->cleanup != NULL) {
pthread_cleanup_pop(1);
}
- if (_thread_run->attr.cleanup_attr != NULL) {
- _thread_run->attr.cleanup_attr(_thread_run->attr.arg_attr);
+ if (curthread->attr.cleanup_attr != NULL) {
+ curthread->attr.cleanup_attr(curthread->attr.arg_attr);
}
/* Check if there is thread specific data: */
- if (_thread_run->specific_data != NULL) {
+ if (curthread->specific_data != NULL) {
/* Run the thread-specific data destructors: */
_thread_cleanupspecific();
}
@@ -179,9 +180,9 @@ pthread_exit(void *status)
_thread_kern_sig_defer();
/* Check if there are any threads joined to this one: */
- while ((pthread = TAILQ_FIRST(&(_thread_run->join_queue))) != NULL) {
+ while ((pthread = TAILQ_FIRST(&(curthread->join_queue))) != NULL) {
/* Remove the thread from the queue: */
- TAILQ_REMOVE(&_thread_run->join_queue, pthread, qe);
+ TAILQ_REMOVE(&curthread->join_queue, pthread, qe);
/* Wake the joined thread and let it detach this thread: */
PTHREAD_NEW_STATE(pthread,PS_RUNNING);
@@ -200,7 +201,7 @@ pthread_exit(void *status)
PANIC("Cannot lock gc mutex");
/* Add this thread to the list of dead threads. */
- TAILQ_INSERT_HEAD(&_dead_list, _thread_run, dle);
+ TAILQ_INSERT_HEAD(&_dead_list, curthread, dle);
/*
* Defer signals to protect the scheduling queues from access
@@ -209,7 +210,7 @@ pthread_exit(void *status)
_thread_kern_sig_defer();
/* Remove this thread from the thread list: */
- TAILQ_REMOVE(&_thread_list, _thread_run, tle);
+ TAILQ_REMOVE(&_thread_list, curthread, tle);
/*
* Undefer and handle pending signals, yielding if necessary:
@@ -227,7 +228,7 @@ pthread_exit(void *status)
* Mark the thread as dead so it will not return if it
* gets context switched out when the mutex is unlocked.
*/
- PTHREAD_SET_STATE(_thread_run, PS_DEAD);
+ PTHREAD_SET_STATE(curthread, PS_DEAD);
/* Unlock the garbage collector mutex: */
if (pthread_mutex_unlock(&_gc_mutex) != 0)
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
diff --git a/lib/libpthread/uthread/uthread_fork.c b/lib/libpthread/uthread/uthread_fork.c
index 5f9054a332b..0271e822526 100644
--- a/lib/libpthread/uthread/uthread_fork.c
+++ b/lib/libpthread/uthread/uthread_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_fork.c,v 1.9 2000/01/06 07:17:09 d Exp $ */
+/* $OpenBSD: uthread_fork.c,v 1.10 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -44,6 +44,7 @@
pid_t
fork(void)
{
+ struct pthread *curthread = _get_curthread();
int i, flags;
pid_t ret;
pthread_t pthread;
@@ -63,7 +64,7 @@ fork(void)
_thread_sys_close(_thread_kern_pipe[1]);
/* Reset signals pending for the running thread: */
- sigemptyset(&_thread_run->sigpend);
+ sigemptyset(&curthread->sigpend);
/*
* Create a pipe that is written to by the signal handler to
@@ -117,7 +118,7 @@ fork(void)
TAILQ_REMOVE(&_thread_list, pthread, tle);
/* Make sure this isn't the running thread: */
- if (pthread != _thread_run) {
+ if (pthread != curthread) {
/* XXX should let gc do all this. */
if(pthread->stack != NULL)
_thread_stack_free(pthread->stack);
@@ -133,7 +134,7 @@ fork(void)
}
/* Restore the running thread */
- TAILQ_INSERT_HEAD(&_thread_list, _thread_run, tle);
+ TAILQ_INSERT_HEAD(&_thread_list, curthread, tle);
/* Re-init the dead thread list: */
TAILQ_INIT(&_dead_list);
@@ -143,7 +144,7 @@ fork(void)
TAILQ_INIT(&_workq);
/* Re-init the threads mutex queue: */
- TAILQ_INIT(&_thread_run->mutexq);
+ TAILQ_INIT(&curthread->mutexq);
/* No spinlocks yet: */
_spinblock_count = 0;
diff --git a/lib/libpthread/uthread/uthread_gc.c b/lib/libpthread/uthread/uthread_gc.c
index 954a09e03df..5f4e520d6aa 100644
--- a/lib/libpthread/uthread/uthread_gc.c
+++ b/lib/libpthread/uthread/uthread_gc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_gc.c,v 1.9 2000/01/06 07:17:23 d Exp $ */
+/* $OpenBSD: uthread_gc.c,v 1.10 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -48,6 +48,7 @@
pthread_addr_t
_thread_gc(pthread_addr_t arg)
{
+ struct pthread *curthread = _get_curthread();
int f_debug;
int f_done = 0;
int ret;
@@ -62,13 +63,13 @@ _thread_gc(pthread_addr_t arg)
sigprocmask (SIG_BLOCK, &mask, NULL);
/* Mark this thread as a library thread (not a user thread). */
- _thread_run->flags |= PTHREAD_FLAGS_PRIVATE;
+ curthread->flags |= PTHREAD_FLAGS_PRIVATE;
/* Set a debug flag based on an environment variable. */
f_debug = (getenv("LIBC_R_DEBUG") != NULL);
/* Set the name of this thread. */
- pthread_set_name_np(_thread_run,"GC");
+ pthread_set_name_np(curthread,"GC");
while (!f_done) {
/* Check if debugging this application. */
@@ -83,8 +84,8 @@ _thread_gc(pthread_addr_t arg)
_thread_kern_sig_defer();
/* Check if this is the last running thread: */
- if (TAILQ_FIRST(&_thread_list) == _thread_run &&
- TAILQ_NEXT(_thread_run, tle) == NULL)
+ if (TAILQ_FIRST(&_thread_list) == curthread &&
+ TAILQ_NEXT(curthread, tle) == NULL)
/*
* This is the last thread, so it can exit
* now.
diff --git a/lib/libpthread/uthread/uthread_info.c b/lib/libpthread/uthread/uthread_info.c
index dac30c7e6c4..fc2f739962c 100644
--- a/lib/libpthread/uthread/uthread_info.c
+++ b/lib/libpthread/uthread/uthread_info.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_info.c,v 1.9 1999/11/25 06:57:04 d Exp $ */
+/* $OpenBSD: uthread_info.c,v 1.10 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -74,6 +74,7 @@ static const struct s_thread_info thread_info[] = {
void
_thread_dump_info(void)
{
+ struct pthread *curthread = _get_curthread();
char s[512];
int fd;
int i;
@@ -127,7 +128,7 @@ _thread_dump_info(void)
_thread_sys_write(fd, s, strlen(s));
/* Check if this is the running thread: */
- if (pthread == _thread_run) {
+ if (pthread == curthread) {
/* Output a record for the running thread: */
strcpy(s, "This is the running thread\n");
_thread_sys_write(fd, s, strlen(s));
diff --git a/lib/libpthread/uthread/uthread_join.c b/lib/libpthread/uthread/uthread_join.c
index 374a5d45b90..310e5521268 100644
--- a/lib/libpthread/uthread/uthread_join.c
+++ b/lib/libpthread/uthread/uthread_join.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_join.c,v 1.6 1999/11/25 07:01:37 d Exp $ */
+/* $OpenBSD: uthread_join.c,v 1.7 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -40,6 +40,7 @@
int
pthread_join(pthread_t pthread, void **thread_return)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
/* This is a cancellation point: */
@@ -51,7 +52,7 @@ pthread_join(pthread_t pthread, void **thread_return)
ret = EINVAL;
/* Check if the caller has specified itself: */
- else if (pthread == _thread_run)
+ else if (pthread == curthread)
/* Avoid a deadlock condition: */
ret = EDEADLK;
@@ -72,7 +73,7 @@ pthread_join(pthread_t pthread, void **thread_return)
/* Check if the thread is not dead: */
else if (pthread->state != PS_DEAD) {
/* Add the running thread to the join queue: */
- TAILQ_INSERT_TAIL(&(pthread->join_queue), _thread_run, qe);
+ TAILQ_INSERT_TAIL(&(pthread->join_queue), curthread, qe);
/* Schedule the next thread: */
_thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__);
diff --git a/lib/libpthread/uthread/uthread_kern.c b/lib/libpthread/uthread/uthread_kern.c
index 016dfc90a69..2376af06534 100644
--- a/lib/libpthread/uthread/uthread_kern.c
+++ b/lib/libpthread/uthread/uthread_kern.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_kern.c,v 1.12 2001/08/15 23:53:17 fgsch Exp $ */
+/* $OpenBSD: uthread_kern.c,v 1.13 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -75,6 +75,7 @@ _thread_check_cancel()
void
_thread_kern_sched(struct sigcontext * scp)
{
+ struct pthread *curthread = _get_curthread();
pthread_t pthread, pthread_h = NULL;
pthread_t old_thread_run;
struct itimerval itimer;
@@ -335,7 +336,8 @@ _thread_kern_sched(struct sigcontext * scp)
* the running thread to point to the global kernel
* thread structure:
*/
- _thread_run = &_thread_kern_thread;
+ _set_curthread(&_thread_kern_thread);
+ curthread = &_thread_kern_thread;
/* Unprotect the scheduling queues: */
_queue_signals = 0;
@@ -413,14 +415,15 @@ _thread_kern_sched(struct sigcontext * scp)
}
/* Make the selected thread the current thread: */
- _thread_run = pthread_h;
+ _set_curthread(pthread_h);
+ curthread = pthread_h;
/*
* Save the current time as the time that the thread
* became active:
*/
- _thread_run->last_active.tv_sec = tv.tv_sec;
- _thread_run->last_active.tv_usec = tv.tv_usec;
+ curthread->last_active.tv_sec = tv.tv_sec;
+ curthread->last_active.tv_usec = tv.tv_usec;
/*
* Define the maximum time before a scheduling signal
@@ -578,6 +581,8 @@ _thread_kern_sched(struct sigcontext * scp)
void
_thread_kern_sched_state(enum pthread_state state, const char *fname, int lineno)
{
+ struct pthread *curthread = _get_curthread();
+
/*
* Flag the pthread kernel as executing scheduler code
* to avoid a scheduler signal from interrupting this
@@ -592,19 +597,20 @@ _thread_kern_sched_state(enum pthread_state state, const char *fname, int lineno
_queue_signals = 1;
/* Change the state of the current thread: */
- _thread_run->state = state;
- _thread_run->fname = fname;
- _thread_run->lineno = lineno;
+ curthread->state = state;
+ curthread->fname = fname;
+ curthread->lineno = lineno;
/* Schedule the next thread that is ready: */
_thread_kern_sched(NULL);
- return;
}
void
_thread_kern_sched_state_unlock(enum pthread_state state,
spinlock_t *lock, char *fname, int lineno)
{
+ struct pthread *curthread = _get_curthread();
+
/*
* Flag the pthread kernel as executing scheduler code
* to avoid a scheduler signal from interrupting this
@@ -620,15 +626,14 @@ _thread_kern_sched_state_unlock(enum pthread_state state,
_queue_signals = 1;
/* Change the state of the current thread: */
- _thread_run->state = state;
- _thread_run->fname = fname;
- _thread_run->lineno = lineno;
+ curthread->state = state;
+ curthread->fname = fname;
+ curthread->lineno = lineno;
_SPINUNLOCK(lock);
/* Schedule the next thread that is ready: */
_thread_kern_sched(NULL);
- return;
}
static void
@@ -963,11 +968,12 @@ _thread_kern_poll(int wait_reqd)
void
_thread_kern_set_timeout(const struct timespec * timeout)
{
+ struct pthread *curthread = _get_curthread();
struct timespec current_time;
struct timeval tv;
/* Reset the timeout flag for the running thread: */
- _thread_run->timeout = 0;
+ curthread->timeout = 0;
/* Check if the thread is to wait forever: */
if (timeout == NULL) {
@@ -975,28 +981,28 @@ _thread_kern_set_timeout(const struct timespec * timeout)
* Set the wakeup time to something that can be recognised as
* different to an actual time of day:
*/
- _thread_run->wakeup_time.tv_sec = -1;
- _thread_run->wakeup_time.tv_nsec = -1;
+ curthread->wakeup_time.tv_sec = -1;
+ curthread->wakeup_time.tv_nsec = -1;
}
/* Check if no waiting is required: */
else if (timeout->tv_sec == 0 && timeout->tv_nsec == 0) {
/* Set the wake up time to 'immediately': */
- _thread_run->wakeup_time.tv_sec = 0;
- _thread_run->wakeup_time.tv_nsec = 0;
+ curthread->wakeup_time.tv_sec = 0;
+ curthread->wakeup_time.tv_nsec = 0;
} else {
/* Get the current time: */
gettimeofday(&tv, NULL);
TIMEVAL_TO_TIMESPEC(&tv, &current_time);
/* Calculate the time for the current thread to wake up: */
- _thread_run->wakeup_time.tv_sec = current_time.tv_sec + timeout->tv_sec;
- _thread_run->wakeup_time.tv_nsec = current_time.tv_nsec + timeout->tv_nsec;
+ curthread->wakeup_time.tv_sec = current_time.tv_sec + timeout->tv_sec;
+ curthread->wakeup_time.tv_nsec = current_time.tv_nsec + timeout->tv_nsec;
/* Check if the nanosecond field needs to wrap: */
- if (_thread_run->wakeup_time.tv_nsec >= 1000000000) {
+ if (curthread->wakeup_time.tv_nsec >= 1000000000) {
/* Wrap the nanosecond field: */
- _thread_run->wakeup_time.tv_sec += 1;
- _thread_run->wakeup_time.tv_nsec -= 1000000000;
+ curthread->wakeup_time.tv_sec += 1;
+ curthread->wakeup_time.tv_nsec -= 1000000000;
}
}
return;
@@ -1005,13 +1011,16 @@ _thread_kern_set_timeout(const struct timespec * timeout)
void
_thread_kern_sig_defer(void)
{
+ struct pthread *curthread = _get_curthread();
+
/* Allow signal deferral to be recursive. */
- _thread_run->sig_defer_count++;
+ curthread->sig_defer_count++;
}
void
_thread_kern_sig_undefer(void)
{
+ struct pthread *curthread = _get_curthread();
pthread_t pthread;
int need_resched = 0;
@@ -1019,20 +1028,20 @@ _thread_kern_sig_undefer(void)
* Perform checks to yield only if we are about to undefer
* signals.
*/
- if (_thread_run->sig_defer_count > 1) {
+ if (curthread->sig_defer_count > 1) {
/* Decrement the signal deferral count. */
- _thread_run->sig_defer_count--;
+ curthread->sig_defer_count--;
}
- else if (_thread_run->sig_defer_count == 1) {
+ else if (curthread->sig_defer_count == 1) {
/* Reenable signals: */
- _thread_run->sig_defer_count = 0;
+ curthread->sig_defer_count = 0;
/*
* Check if there are queued signals:
*/
while (_sigq_check_reqd != 0) {
/* Defer scheduling while we process queued signals: */
- _thread_run->sig_defer_count = 1;
+ curthread->sig_defer_count = 1;
/* Clear the flag before checking the signal queue: */
_sigq_check_reqd = 0;
@@ -1047,17 +1056,17 @@ _thread_kern_sig_undefer(void)
*/
if ((need_resched == 0) &&
(((pthread = PTHREAD_PRIOQ_FIRST()) != NULL) &&
- (pthread->active_priority > _thread_run->active_priority))) {
+ (pthread->active_priority > curthread->active_priority))) {
need_resched = 1;
}
/* Reenable signals: */
- _thread_run->sig_defer_count = 0;
+ curthread->sig_defer_count = 0;
}
/* Yield the CPU if necessary: */
- if (need_resched || _thread_run->yield_on_sig_undefer != 0) {
- _thread_run->yield_on_sig_undefer = 0;
+ if (need_resched || curthread->yield_on_sig_undefer != 0) {
+ curthread->yield_on_sig_undefer = 0;
_thread_kern_sched(NULL);
}
}
@@ -1119,4 +1128,19 @@ thread_run_switch_hook(pthread_t thread_out, pthread_t thread_in)
_sched_switch_hook(tid_out, tid_in);
}
}
+
+struct pthread *
+_get_curthread(void)
+{
+ if (_thread_initial == NULL)
+ _thread_init();
+
+ return (_thread_run);
+}
+
+void
+_set_curthread(struct pthread *newthread)
+{
+ _thread_run = newthread;
+}
#endif
diff --git a/lib/libpthread/uthread/uthread_kevent.c b/lib/libpthread/uthread/uthread_kevent.c
index 0985d05d38a..909f92366db 100644
--- a/lib/libpthread/uthread/uthread_kevent.c
+++ b/lib/libpthread/uthread/uthread_kevent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_kevent.c,v 1.1 2001/08/15 23:50:34 fgsch Exp $ */
+/* $OpenBSD: uthread_kevent.c,v 1.2 2001/08/21 19:24:53 fgsch Exp $ */
/*-
* Copyright (c) 2000 Jonathan Lemon <jlemon@flugsvamp.com>
* All rights reserved.
@@ -40,6 +40,7 @@ int
kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents, const struct timespec *timeout)
{
+ struct pthread *curthread = _get_curthread();
struct timespec nullts = { 0, 0 };
int rc;
@@ -51,26 +52,26 @@ kevent(int kq, const struct kevent *changelist, int nchanges,
if (rc == 0 && (timeout == NULL ||
timeout->tv_sec != 0 || timeout->tv_nsec != 0)) {
/* Save the socket file descriptor: */
- _thread_run->data.fd.fd = kq;
- _thread_run->data.fd.fname = __FILE__;
- _thread_run->data.fd.branch = __LINE__;
+ curthread->data.fd.fd = kq;
+ curthread->data.fd.fname = __FILE__;
+ curthread->data.fd.branch = __LINE__;
do {
/* Reset the interrupted and timeout flags: */
- _thread_run->interrupted = 0;
- _thread_run->timeout = 0;
+ curthread->interrupted = 0;
+ curthread->timeout = 0;
_thread_kern_sched_state(PS_FDR_WAIT,
__FILE__, __LINE__);
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
rc = -1;
break;
}
rc = _thread_sys_kevent(kq, NULL, 0,
eventlist, nevents, &nullts);
- } while (rc == 0 && _thread_run->timeout == 0);
+ } while (rc == 0 && curthread->timeout == 0);
}
return (rc);
}
diff --git a/lib/libpthread/uthread/uthread_nanosleep.c b/lib/libpthread/uthread/uthread_nanosleep.c
index 583e94e983f..4518a13e91c 100644
--- a/lib/libpthread/uthread/uthread_nanosleep.c
+++ b/lib/libpthread/uthread/uthread_nanosleep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_nanosleep.c,v 1.5 1999/11/25 07:01:40 d Exp $ */
+/* $OpenBSD: uthread_nanosleep.c,v 1.6 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -42,6 +42,7 @@ int
nanosleep(const struct timespec * time_to_sleep,
struct timespec * time_remaining)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
struct timespec current_time;
struct timespec current_time1;
@@ -63,16 +64,16 @@ nanosleep(const struct timespec * time_to_sleep,
TIMEVAL_TO_TIMESPEC(&tv, &current_time);
/* Calculate the time for the current thread to wake up: */
- _thread_run->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec;
- _thread_run->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec;
+ curthread->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec;
+ curthread->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec;
/* Check if the nanosecond field has overflowed: */
- if (_thread_run->wakeup_time.tv_nsec >= 1000000000) {
+ if (curthread->wakeup_time.tv_nsec >= 1000000000) {
/* Wrap the nanosecond field: */
- _thread_run->wakeup_time.tv_sec += 1;
- _thread_run->wakeup_time.tv_nsec -= 1000000000;
+ curthread->wakeup_time.tv_sec += 1;
+ curthread->wakeup_time.tv_nsec -= 1000000000;
}
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
/* Reschedule the current thread to sleep: */
_thread_kern_sched_state(PS_SLEEP_WAIT, __FILE__, __LINE__);
@@ -114,7 +115,7 @@ nanosleep(const struct timespec * time_to_sleep,
}
/* Check if the sleep was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an EINTR error : */
errno = EINTR;
ret = -1;
diff --git a/lib/libpthread/uthread/uthread_poll.c b/lib/libpthread/uthread/uthread_poll.c
index 022b46f308b..6119eda2f34 100644
--- a/lib/libpthread/uthread/uthread_poll.c
+++ b/lib/libpthread/uthread/uthread_poll.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_poll.c,v 1.5 2001/08/15 15:47:56 fgsch Exp $ */
+/* $OpenBSD: uthread_poll.c,v 1.6 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1999 Daniel Eischen <eischen@vigrid.com>
* All rights reserved.
@@ -47,6 +47,7 @@
int
poll(struct pollfd fds[], int nfds, int timeout)
{
+ struct pthread *curthread = _get_curthread();
struct timespec ts;
int numfds = nfds;
int i, ret = 0;
@@ -84,10 +85,10 @@ poll(struct pollfd fds[], int nfds, int timeout)
fds[i].revents = 0;
}
- _thread_run->data.poll_data = &data;
- _thread_run->interrupted = 0;
+ curthread->data.poll_data = &data;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_POLL_WAIT, __FILE__, __LINE__);
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
} else {
diff --git a/lib/libpthread/uthread/uthread_read.c b/lib/libpthread/uthread/uthread_read.c
index eb049a6cf57..b491ea99116 100644
--- a/lib/libpthread/uthread/uthread_read.c
+++ b/lib/libpthread/uthread/uthread_read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_read.c,v 1.6 2001/08/17 06:50:25 fgsch Exp $ */
+/* $OpenBSD: uthread_read.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.
@@ -45,6 +45,7 @@
ssize_t
read(int fd, void *buf, size_t nbytes)
{
+ struct pthread *curthread = _get_curthread();
ssize_t ret;
int type;
@@ -71,11 +72,11 @@ read(int fd, void *buf, size_t nbytes)
else while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) {
if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDR_WAIT,
__FILE__, __LINE__);
@@ -84,7 +85,7 @@ read(int fd, void *buf, size_t nbytes)
* Check if the operation was
* interrupted by a signal
*/
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libpthread/uthread/uthread_readv.c b/lib/libpthread/uthread/uthread_readv.c
index 4a91f7cb887..05661166b4c 100644
--- a/lib/libpthread/uthread/uthread_readv.c
+++ b/lib/libpthread/uthread/uthread_readv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_readv.c,v 1.4 2001/08/17 06:52:23 fgsch Exp $ */
+/* $OpenBSD: uthread_readv.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -45,6 +45,7 @@
ssize_t
readv(int fd, const struct iovec * iov, int iovcnt)
{
+ struct pthread *curthread = _get_curthread();
ssize_t ret;
int type;
@@ -65,11 +66,11 @@ readv(int fd, const struct iovec * iov, int iovcnt)
while ((ret = _thread_sys_readv(fd, iov, iovcnt)) < 0) {
if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 &&
(errno == EWOULDBLOCK || errno == EAGAIN)) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDR_WAIT,
__FILE__, __LINE__);
@@ -78,7 +79,7 @@ readv(int fd, const struct iovec * iov, int iovcnt)
* Check if the operation was
* interrupted by a signal
*/
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libpthread/uthread/uthread_recvfrom.c b/lib/libpthread/uthread/uthread_recvfrom.c
index 18c0c6ce8ed..fee722f0b68 100644
--- a/lib/libpthread/uthread/uthread_recvfrom.c
+++ b/lib/libpthread/uthread/uthread_recvfrom.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_recvfrom.c,v 1.4 1999/11/25 07:01:42 d Exp $ */
+/* $OpenBSD: uthread_recvfrom.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,20 +43,21 @@
ssize_t
recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from, socklen_t *from_len)
{
+ struct pthread *curthread = _get_curthread();
int ret;
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;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
/* Check if the wait was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error status: */
errno = EINTR;
ret = -1;
diff --git a/lib/libpthread/uthread/uthread_recvmsg.c b/lib/libpthread/uthread/uthread_recvmsg.c
index c92b7a1c420..73fa874b123 100644
--- a/lib/libpthread/uthread/uthread_recvmsg.c
+++ b/lib/libpthread/uthread/uthread_recvmsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_recvmsg.c,v 1.3 1999/11/25 07:01:42 d Exp $ */
+/* $OpenBSD: uthread_recvmsg.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,20 +43,21 @@
ssize_t
recvmsg(int fd, struct msghdr *msg, int flags)
{
+ struct pthread *curthread = _get_curthread();
int ret;
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;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__);
/* Check if the wait was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error status: */
errno = EINTR;
ret = -1;
diff --git a/lib/libpthread/uthread/uthread_select.c b/lib/libpthread/uthread/uthread_select.c
index a7cd5c3d260..61708fa7c39 100644
--- a/lib/libpthread/uthread/uthread_select.c
+++ b/lib/libpthread/uthread/uthread_select.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_select.c,v 1.4 1999/11/25 07:01:42 d Exp $ */
+/* $OpenBSD: uthread_select.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -49,6 +49,7 @@ int
select(int numfds, fd_set * readfds, fd_set * writefds,
fd_set * exceptfds, struct timeval * timeout)
{
+ struct pthread *curthread = _get_curthread();
struct timespec ts;
int i, ret = 0, f_wait = 1;
int pfd_index, got_one = 0, fd_count = 0;
@@ -92,9 +93,9 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
* Allocate memory for poll data if it hasn't already been
* allocated or if previously allocated memory is insufficient.
*/
- if ((_thread_run->poll_data.fds == NULL) ||
- (_thread_run->poll_data.nfds < fd_count)) {
- data.fds = (struct pollfd *) realloc(_thread_run->poll_data.fds,
+ if ((curthread->poll_data.fds == NULL) ||
+ (curthread->poll_data.nfds < fd_count)) {
+ data.fds = (struct pollfd *) realloc(curthread->poll_data.fds,
sizeof(struct pollfd) * MAX(128, fd_count));
if (data.fds == NULL) {
errno = ENOMEM;
@@ -106,13 +107,13 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
* indicates what is allocated, not what is
* currently being polled.
*/
- _thread_run->poll_data.fds = data.fds;
- _thread_run->poll_data.nfds = MAX(128, fd_count);
+ curthread->poll_data.fds = data.fds;
+ curthread->poll_data.nfds = MAX(128, fd_count);
}
}
if (ret == 0) {
/* Setup the wait data. */
- data.fds = _thread_run->poll_data.fds;
+ data.fds = curthread->poll_data.fds;
data.nfds = fd_count;
/*
@@ -145,10 +146,10 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
}
if (((ret = _thread_sys_poll(data.fds, data.nfds, 0)) == 0) &&
(f_wait != 0)) {
- _thread_run->data.poll_data = &data;
- _thread_run->interrupted = 0;
+ curthread->data.poll_data = &data;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_SELECT_WAIT, __FILE__, __LINE__);
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
data.nfds = 0;
ret = -1;
diff --git a/lib/libpthread/uthread/uthread_self.c b/lib/libpthread/uthread/uthread_self.c
index 0ff4f7f3ba6..5c0c53c4cbc 100644
--- a/lib/libpthread/uthread/uthread_self.c
+++ b/lib/libpthread/uthread/uthread_self.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_self.c,v 1.3 1999/11/25 07:01:43 d Exp $ */
+/* $OpenBSD: uthread_self.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -40,6 +40,6 @@ pthread_t
pthread_self(void)
{
/* Return the running thread pointer: */
- return (_thread_run);
+ return (_get_curthread());
}
#endif
diff --git a/lib/libpthread/uthread/uthread_sendmsg.c b/lib/libpthread/uthread/uthread_sendmsg.c
index 36bc6a62439..11d91d85c5c 100644
--- a/lib/libpthread/uthread/uthread_sendmsg.c
+++ b/lib/libpthread/uthread/uthread_sendmsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sendmsg.c,v 1.3 1999/11/25 07:01:43 d Exp $ */
+/* $OpenBSD: uthread_sendmsg.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,20 +43,21 @@
ssize_t
sendmsg(int fd, const struct msghdr *msg, int flags)
{
+ struct pthread *curthread = _get_curthread();
int ret;
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;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__);
/* Check if the operation was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libpthread/uthread/uthread_sendto.c b/lib/libpthread/uthread/uthread_sendto.c
index b0a8c059a1e..062d11e77ac 100644
--- a/lib/libpthread/uthread/uthread_sendto.c
+++ b/lib/libpthread/uthread/uthread_sendto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sendto.c,v 1.4 1999/11/25 07:01:43 d Exp $ */
+/* $OpenBSD: uthread_sendto.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -43,20 +43,21 @@
ssize_t
sendto(int fd, const void *msg, size_t len, int flags, const struct sockaddr * to, socklen_t to_len)
{
+ struct pthread *curthread = _get_curthread();
int ret;
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;
+ curthread->data.fd.fd = fd;
/* Set the timeout: */
_thread_kern_set_timeout(NULL);
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__);
/* Check if the operation was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libpthread/uthread/uthread_sig.c b/lib/libpthread/uthread/uthread_sig.c
index 1cdbc362aa6..56aea46c28f 100644
--- a/lib/libpthread/uthread/uthread_sig.c
+++ b/lib/libpthread/uthread/uthread_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sig.c,v 1.7 2000/01/06 07:20:52 d Exp $ */
+/* $OpenBSD: uthread_sig.c,v 1.8 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -65,6 +65,7 @@ _thread_sig_init(void)
void
_thread_sig_handler(int sig, int code, struct sigcontext * scp)
{
+ struct pthread *curthread = _get_curthread();
char c;
int i;
@@ -81,8 +82,8 @@ _thread_sig_handler(int sig, int code, struct sigcontext * scp)
* the currently running thread has deferred thread
* signals.
*/
- else if (_thread_run->sig_defer_count > 0)
- _thread_run->yield_on_sig_undefer = 1;
+ else if (curthread->sig_defer_count > 0)
+ curthread->yield_on_sig_undefer = 1;
else {
/*
@@ -105,7 +106,7 @@ _thread_sig_handler(int sig, int code, struct sigcontext * scp)
* running thread that has deferred signals.
*/
else if ((_queue_signals != 0) || ((_thread_kern_in_sched == 0) &&
- (_thread_run->sig_defer_count > 0))) {
+ (curthread->sig_defer_count > 0))) {
/* Cast the signal number to a character variable: */
c = sig;
@@ -151,6 +152,7 @@ _thread_sig_handler(int sig, int code, struct sigcontext * scp)
void
_thread_sig_handle(int sig, struct sigcontext * scp)
{
+ struct pthread *curthread = _get_curthread();
int i;
pthread_t pthread, pthread_next;
@@ -238,13 +240,13 @@ _thread_sig_handle(int sig, struct sigcontext * scp)
* list:
*/
TAILQ_FOREACH(pthread, &_thread_list, tle) {
- pthread_t pthread_saved = _thread_run;
+ pthread_t pthread_saved = curthread;
/* Current thread inside critical region? */
- if (_thread_run->sig_defer_count > 0)
+ if (curthread->sig_defer_count > 0)
pthread->sig_defer_count++;
- _thread_run = pthread;
+ curthread = pthread;
_thread_signal(pthread,sig);
/*
@@ -252,10 +254,10 @@ _thread_sig_handle(int sig, struct sigcontext * scp)
* running thread:
*/
_dispatch_signals();
- _thread_run = pthread_saved;
+ curthread = pthread_saved;
/* Current thread inside critical region? */
- if (_thread_run->sig_defer_count > 0)
+ if (curthread->sig_defer_count > 0)
pthread->sig_defer_count--;
}
}
@@ -362,13 +364,14 @@ _thread_signal(pthread_t pthread, int sig)
void
_dispatch_signals()
{
+ struct pthread *curthread = _get_curthread();
int i;
/*
* Check if there are pending signals for the running
* thread that aren't blocked:
*/
- if ((_thread_run->sigpend & ~_thread_run->sigmask) != 0)
+ if ((curthread->sigpend & ~curthread->sigmask) != 0)
/* Look for all possible pending signals: */
for (i = 1; i < NSIG; i++)
/*
@@ -377,10 +380,10 @@ _dispatch_signals()
*/
if (_thread_sigact[i - 1].sa_handler != SIG_DFL &&
_thread_sigact[i - 1].sa_handler != SIG_IGN &&
- sigismember(&_thread_run->sigpend,i) &&
- !sigismember(&_thread_run->sigmask,i)) {
+ sigismember(&curthread->sigpend,i) &&
+ !sigismember(&curthread->sigmask,i)) {
/* Clear the pending signal: */
- sigdelset(&_thread_run->sigpend,i);
+ sigdelset(&curthread->sigpend,i);
/*
* Dispatch the signal via the custom signal
diff --git a/lib/libpthread/uthread/uthread_sigmask.c b/lib/libpthread/uthread/uthread_sigmask.c
index 6de570535e4..03fb4963395 100644
--- a/lib/libpthread/uthread/uthread_sigmask.c
+++ b/lib/libpthread/uthread/uthread_sigmask.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sigmask.c,v 1.3 1999/11/25 07:01:44 d Exp $ */
+/* $OpenBSD: uthread_sigmask.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -41,12 +41,13 @@
int
pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
/* Check if the existing signal process mask is to be returned: */
if (oset != NULL) {
/* Return the current mask: */
- *oset = _thread_run->sigmask;
+ *oset = curthread->sigmask;
}
/* Check if a new signal set was provided by the caller: */
if (set != NULL) {
@@ -55,19 +56,19 @@ pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
/* Block signals: */
case SIG_BLOCK:
/* Add signals to the existing mask: */
- _thread_run->sigmask |= *set;
+ curthread->sigmask |= *set;
break;
/* Unblock signals: */
case SIG_UNBLOCK:
/* Clear signals from the existing mask: */
- _thread_run->sigmask &= ~(*set);
+ curthread->sigmask &= ~(*set);
break;
/* Set the signal process mask: */
case SIG_SETMASK:
/* Set the new mask: */
- _thread_run->sigmask = *set;
+ curthread->sigmask = *set;
break;
/* Trap invalid actions: */
diff --git a/lib/libpthread/uthread/uthread_sigpending.c b/lib/libpthread/uthread/uthread_sigpending.c
index 9921ee5a237..911d1b4b891 100644
--- a/lib/libpthread/uthread/uthread_sigpending.c
+++ b/lib/libpthread/uthread/uthread_sigpending.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sigpending.c,v 1.2 1999/11/25 07:01:45 d Exp $ */
+/* $OpenBSD: uthread_sigpending.c,v 1.3 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1999 Daniel Eischen <eischen@vigrid.com>.
* All rights reserved.
@@ -41,6 +41,7 @@
int
sigpending(sigset_t * set)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
/* Check for a null signal set pointer: */
@@ -49,7 +50,7 @@ sigpending(sigset_t * set)
ret = EINVAL;
}
else {
- *set = _thread_run->sigpend;
+ *set = curthread->sigpend;
}
/* Return the completion status: */
return (ret);
diff --git a/lib/libpthread/uthread/uthread_sigsuspend.c b/lib/libpthread/uthread/uthread_sigsuspend.c
index bd7e2094bd9..bbf9c7c9870 100644
--- a/lib/libpthread/uthread/uthread_sigsuspend.c
+++ b/lib/libpthread/uthread/uthread_sigsuspend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sigsuspend.c,v 1.4 1999/11/25 07:01:45 d Exp $ */
+/* $OpenBSD: uthread_sigsuspend.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -41,16 +41,19 @@
int
sigsuspend(const sigset_t * set)
{
+ struct pthread *curthread = _get_curthread();
int ret = -1;
sigset_t oset;
+ _thread_enter_cancellation_point();
+
/* Check if a new signal set was provided by the caller: */
if (set != NULL) {
/* Save the current signal mask: */
- oset = _thread_run->sigmask;
+ oset = curthread->sigmask;
/* Change the caller's mask: */
- _thread_run->sigmask = *set;
+ curthread->sigmask = *set;
/* Wait for a signal: */
_thread_kern_sched_state(PS_SIGSUSPEND, __FILE__, __LINE__);
@@ -59,12 +62,14 @@ sigsuspend(const sigset_t * set)
errno = EINTR;
/* Restore the signal mask: */
- _thread_run->sigmask = oset;
+ curthread->sigmask = oset;
} else {
/* Return an invalid argument error: */
errno = EINVAL;
}
+ _thread_leave_cancellation_point();
+
/* Return the completion status: */
return (ret);
}
diff --git a/lib/libpthread/uthread/uthread_sigwait.c b/lib/libpthread/uthread/uthread_sigwait.c
index abcc1d6e894..1ae76ab1926 100644
--- a/lib/libpthread/uthread/uthread_sigwait.c
+++ b/lib/libpthread/uthread/uthread_sigwait.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sigwait.c,v 1.8 2000/01/06 07:21:14 d Exp $ */
+/* $OpenBSD: uthread_sigwait.c,v 1.9 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -41,6 +41,7 @@
int
sigwait(const sigset_t * set, int *sig)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
int i;
sigset_t tempset, waitset;
@@ -72,7 +73,7 @@ sigwait(const sigset_t * set, int *sig)
sigdelset(&waitset, SIGINFO);
/* Check to see if a pending signal is in the wait mask. */
- if ((tempset = (_thread_run->sigpend & waitset)) != 0) {
+ if ((tempset = (curthread->sigpend & waitset)) != 0) {
/* Enter a loop to find a pending signal: */
for (i = 1; i < NSIG; i++) {
if (sigismember (&tempset, i))
@@ -80,7 +81,7 @@ sigwait(const sigset_t * set, int *sig)
}
/* Clear the pending signal: */
- sigdelset(&_thread_run->sigpend,i);
+ sigdelset(&curthread->sigpend,i);
/* Return the signal number to the caller: */
*sig = i;
@@ -115,19 +116,19 @@ sigwait(const sigset_t * set, int *sig)
* mask is independent of the threads signal mask
* and requires separate storage.
*/
- _thread_run->data.sigwait = &waitset;
+ curthread->data.sigwait = &waitset;
/* Wait for a signal: */
_thread_kern_sched_state(PS_SIGWAIT, __FILE__, __LINE__);
/* Return the signal number to the caller: */
- *sig = _thread_run->signo;
+ *sig = curthread->signo;
/*
* Probably unnecessary, but since it's in a union struct
* we don't know how it could be used in the future.
*/
- _thread_run->data.sigwait = NULL;
+ curthread->data.sigwait = NULL;
}
/* Restore the sigactions: */
diff --git a/lib/libpthread/uthread/uthread_single_np.c b/lib/libpthread/uthread/uthread_single_np.c
index 84208893b16..a1820b311bc 100644
--- a/lib/libpthread/uthread/uthread_single_np.c
+++ b/lib/libpthread/uthread/uthread_single_np.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_single_np.c,v 1.3 1999/11/25 07:01:45 d Exp $ */
+/* $OpenBSD: uthread_single_np.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -39,8 +39,10 @@
int pthread_single_np()
{
+ struct pthread *curthread = _get_curthread();
+
/* Enter single-threaded (non-POSIX) scheduling mode: */
- _thread_single = _thread_run;
+ _thread_single = curthread;
return(0);
}
#endif
diff --git a/lib/libpthread/uthread/uthread_spec.c b/lib/libpthread/uthread/uthread_spec.c
index 1ac1df46fe4..b1fdeb9dfa5 100644
--- a/lib/libpthread/uthread/uthread_spec.c
+++ b/lib/libpthread/uthread/uthread_spec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_spec.c,v 1.6 1999/11/25 07:01:46 d Exp $ */
+/* $OpenBSD: uthread_spec.c,v 1.7 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -89,6 +89,7 @@ pthread_key_delete(pthread_key_t key)
void
_thread_cleanupspecific(void)
{
+ struct pthread *curthread = _get_curthread();
void *data;
int key;
int itr;
@@ -96,16 +97,16 @@ _thread_cleanupspecific(void)
for (itr = 0; itr < PTHREAD_DESTRUCTOR_ITERATIONS; itr++) {
for (key = 0; key < PTHREAD_KEYS_MAX; key++) {
- if (_thread_run->specific_data_count) {
+ if (curthread->specific_data_count) {
/* Lock the key table entry: */
_SPINLOCK(&key_table[key].lock);
destructor = data = 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 (curthread->specific_data[key]) {
+ data = (void *) curthread->specific_data[key];
+ curthread->specific_data[key] = NULL;
+ curthread->specific_data_count--;
destructor = key_table[key].destructor;
}
}
@@ -120,14 +121,14 @@ _thread_cleanupspecific(void)
if (destructor)
destructor(data);
} else {
- free(_thread_run->specific_data);
- _thread_run->specific_data = NULL;
+ free(curthread->specific_data);
+ curthread->specific_data = NULL;
return;
}
}
}
- free(_thread_run->specific_data);
- _thread_run->specific_data = NULL;
+ free(curthread->specific_data);
+ curthread->specific_data = NULL;
}
static inline const void **
@@ -143,11 +144,11 @@ pthread_key_allocate_data(void)
int
pthread_setspecific(pthread_key_t key, const void *value)
{
- pthread_t pthread;
- int ret = 0;
+ struct pthread *pthread;
+ int ret = 0;
/* Point to the running thread: */
- pthread = _thread_run;
+ pthread = _get_curthread();
if ((pthread->specific_data) ||
(pthread->specific_data = pthread_key_allocate_data())) {
@@ -174,11 +175,11 @@ pthread_setspecific(pthread_key_t key, const void *value)
void *
pthread_getspecific(pthread_key_t key)
{
- pthread_t pthread;
+ struct pthread *pthread;
void *data;
/* Point to the running thread: */
- pthread = _thread_run;
+ pthread = _get_curthread();
/* Check if there is specific data: */
if (pthread->specific_data != NULL && key < PTHREAD_KEYS_MAX) {
diff --git a/lib/libpthread/uthread/uthread_spinlock.c b/lib/libpthread/uthread/uthread_spinlock.c
index 41381e18321..418ddcf3427 100644
--- a/lib/libpthread/uthread/uthread_spinlock.c
+++ b/lib/libpthread/uthread/uthread_spinlock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_spinlock.c,v 1.7 2000/01/06 07:22:04 d Exp $ */
+/* $OpenBSD: uthread_spinlock.c,v 1.8 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -52,18 +52,20 @@ extern char *__progname;
void
_spinlock(spinlock_t *lck)
{
+ struct pthread *curthread = _get_curthread();
+
/*
* Try to grab the lock and loop if another thread grabs
* it before we do.
*/
while(_atomic_lock(&lck->access_lock)) {
/* Block the thread until the lock. */
- _thread_run->data.spinlock = lck;
+ curthread->data.spinlock = lck;
_thread_kern_sched_state(PS_SPINBLOCK, __FILE__, __LINE__);
}
/* The running thread now owns the lock: */
- lck->lock_owner = _thread_run;
+ lck->lock_owner = curthread;
}
/*
@@ -79,6 +81,7 @@ _spinlock(spinlock_t *lck)
void
_spinlock_debug(spinlock_t *lck, const char *fname, int lineno)
{
+ struct pthread *curthread = _get_curthread();
int cnt = 0;
/*
@@ -89,19 +92,19 @@ _spinlock_debug(spinlock_t *lck, const char *fname, int lineno)
cnt++;
if (cnt > 100) {
char str[256];
- snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, _thread_run, lck, fname, lineno, lck->fname, lck->lineno);
+ snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno);
_thread_sys_write(2,str,strlen(str));
sleep(1);
cnt = 0;
}
/* Block the thread until the lock. */
- _thread_run->data.spinlock = lck;
+ curthread->data.spinlock = lck;
_thread_kern_sched_state(PS_SPINBLOCK, fname, lineno);
}
/* The running thread now owns the lock: */
- lck->lock_owner = _thread_run;
+ lck->lock_owner = curthread;
lck->fname = fname;
lck->lineno = lineno;
}
diff --git a/lib/libpthread/uthread/uthread_wait4.c b/lib/libpthread/uthread/uthread_wait4.c
index 0c3efa803f2..b51d6b29d6c 100644
--- a/lib/libpthread/uthread/uthread_wait4.c
+++ b/lib/libpthread/uthread/uthread_wait4.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_wait4.c,v 1.5 1999/11/25 07:01:47 d Exp $ */
+/* $OpenBSD: uthread_wait4.c,v 1.6 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -41,6 +41,7 @@
pid_t
wait4(pid_t pid, int *istat, int options, struct rusage * rusage)
{
+ struct pthread *curthread = _get_curthread();
pid_t ret;
/* This is a cancellation point: */
@@ -51,13 +52,13 @@ wait4(pid_t pid, int *istat, int options, struct rusage * rusage)
/* Perform a non-blocking wait4 syscall: */
while ((ret = _thread_sys_wait4(pid, istat, options | WNOHANG, rusage)) == 0 && (options & WNOHANG) == 0) {
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
/* Schedule the next thread while this one waits: */
_thread_kern_sched_state(PS_WAIT_WAIT, __FILE__, __LINE__);
/* Check if this call was interrupted by a signal: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
errno = EINTR;
ret = -1;
break;
diff --git a/lib/libpthread/uthread/uthread_write.c b/lib/libpthread/uthread/uthread_write.c
index 05c83bbcd22..09cd9001055 100644
--- a/lib/libpthread/uthread/uthread_write.c
+++ b/lib/libpthread/uthread/uthread_write.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_write.c,v 1.7 2001/08/11 15:01:57 fgsch Exp $ */
+/* $OpenBSD: uthread_write.c,v 1.8 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -45,6 +45,7 @@
ssize_t
write(int fd, const void *buf, size_t nbytes)
{
+ struct pthread *curthread = _get_curthread();
int blocking;
int type;
ssize_t n;
@@ -99,11 +100,11 @@ write(int fd, const void *buf, size_t nbytes)
*/
if (blocking && ((n < 0 && (errno == EWOULDBLOCK ||
errno == EAGAIN)) || (n >= 0 && num < nbytes))) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDW_WAIT,
__FILE__, __LINE__);
@@ -112,7 +113,7 @@ write(int fd, const void *buf, size_t nbytes)
* Check if the operation was
* interrupted by a signal
*/
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error: */
ret = -1;
}
diff --git a/lib/libpthread/uthread/uthread_writev.c b/lib/libpthread/uthread/uthread_writev.c
index be26356d2c9..eb5d6418a98 100644
--- a/lib/libpthread/uthread/uthread_writev.c
+++ b/lib/libpthread/uthread/uthread_writev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_writev.c,v 1.4 2001/08/11 14:56:07 fgsch Exp $ */
+/* $OpenBSD: uthread_writev.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -47,6 +47,7 @@
ssize_t
writev(int fd, const struct iovec * iov, int iovcnt)
{
+ struct pthread *curthread = _get_curthread();
int blocking;
int idx = 0;
int type;
@@ -159,11 +160,11 @@ writev(int fd, const struct iovec * iov, int iovcnt)
*/
if (blocking && ((n < 0 && (errno == EWOULDBLOCK ||
errno == EAGAIN)) || (n >= 0 && idx < iovcnt))) {
- _thread_run->data.fd.fd = fd;
+ curthread->data.fd.fd = fd;
_thread_kern_set_timeout(NULL);
/* Reset the interrupted operation flag: */
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
_thread_kern_sched_state(PS_FDW_WAIT,
__FILE__, __LINE__);
@@ -172,7 +173,7 @@ writev(int fd, const struct iovec * iov, int iovcnt)
* Check if the operation was
* interrupted by a signal
*/
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an error: */
ret = -1;
}
diff --git a/lib/libpthread/uthread/uthread_yield.c b/lib/libpthread/uthread/uthread_yield.c
index 055555dec6d..32852ee847a 100644
--- a/lib/libpthread/uthread/uthread_yield.c
+++ b/lib/libpthread/uthread/uthread_yield.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_yield.c,v 1.4 2001/08/04 14:43:53 fgsch Exp $ */
+/* $OpenBSD: uthread_yield.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -39,8 +39,10 @@
int
sched_yield(void)
{
+ struct pthread *curthread = _get_curthread();
+
/* Reset the accumulated time slice value for the current thread: */
- _thread_run->slice_usec = -1;
+ curthread->slice_usec = -1;
/* Schedule the next thread: */
_thread_kern_sched(NULL);
@@ -53,8 +55,10 @@ sched_yield(void)
void
pthread_yield(void)
{
+ struct pthread *curthread = _get_curthread();
+
/* Reset the accumulated time slice value for the current thread: */
- _thread_run->slice_usec = -1;
+ curthread->slice_usec = -1;
/* Schedule the next thread: */
_thread_kern_sched(NULL);