summaryrefslogtreecommitdiff
path: root/lib/libpthread/uthread/uthread_kern.c
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>2003-01-27 22:22:31 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>2003-01-27 22:22:31 +0000
commitc356b59c59c09b663e2373cbf77a6ce3962c1694 (patch)
treedf10bf685045545eb60831c30a1d770dbdc53070 /lib/libpthread/uthread/uthread_kern.c
parent220bcc2a4a0a756afc843744df1b212ed811f4ce (diff)
pthreads signal handling improvements. With these changes all
of the thread regressions tests pass on i386, sparc, sparc64 (save the siginfo test on sparc64 due to a kernel issue) and alpha. The tests should also pass on ppc. In addition, it fixes the problems with the "mysql torture test" provided by one of our users. The python port also appears to work correctly with these changes. Summary of changes: * check_pending removed from thread structure, no longer used. * unused elements of sigstatus structure removed. The sigstatus structure is now used to keep track of siginfo data instead of defining a local array in uthread_sig.c. * _thread_kern_sched_sig removed * _thread_sig_process goes away -- can't have a lock active when signal handlers are called. Functions now call _thread_sig_handle directly. * _thread_clear_pending now used lib wide to clear pending flags. It was named _clean_pending_flag and only used in uthread_sig.c. The function clears both per thread signals, and per process signals. * _thread_sig_handle now returns a value. * unused debugging macros removed from the thread kernel * dispatch pending signals after switching to a thread providing that signal handling hasn't been deferred by the thread. * process thread switchhooks before dispatching pending sigs * check for thread cancellation before dispatching pending sigs * re-wrote pthread-kill to do the correct thing. It now does minimal thread-kill-specific processing and then calls the existing code in uthread_sig to process the generated signal. * shut the compiler up when compiling uthread_mutex.c * no more "signal_lock". It does more harm than good. * keep track of "per-process" signals. * don't bother saving siginfo_t data for the scheduling signal. * per posix: SIGSTOP cleared when SIGCONT received and vice versa. * add _dispatch_signal to properly dispatch a signal to a thread. It sets the appropriate signal mask, something that was missing in the previous implementation. This fixes several bugs. The previous method held a lock. If the signal handler longjmp-ed the lock was never cleared and no more signals were processed.
Diffstat (limited to 'lib/libpthread/uthread/uthread_kern.c')
-rw-r--r--lib/libpthread/uthread/uthread_kern.c78
1 files changed, 8 insertions, 70 deletions
diff --git a/lib/libpthread/uthread/uthread_kern.c b/lib/libpthread/uthread/uthread_kern.c
index 9930098a974..d72e7b5ed9e 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.24 2003/01/24 21:03:15 marc Exp $ */
+/* $OpenBSD: uthread_kern.c,v 1.25 2003/01/27 22:22:30 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -50,12 +50,6 @@
#include <pthread.h>
#include "pthread_private.h"
-#if defined(PTHREAD_TRACE_KERN)
-#define PTHREAD_TRACE(x) _thread_sys_write(-1, (void*) x, 0)
-#else
-#define PTHREAD_TRACE(x)
-#endif
-
/*
* local functions. Do NOT make these static... we want so see them in
* crash dumps.
@@ -68,16 +62,6 @@ inline void _thread_run_switch_hook(pthread_t, pthread_t);
static int last_tick = 0;
void
-_thread_kern_sched_sig(void)
-{
- struct pthread *curthread = _get_curthread();
-
- PTHREAD_TRACE(1);
- curthread->check_pending = 1;
- _thread_kern_sched(NULL);
-}
-
-void
_thread_kern_sched(struct sigcontext * scp)
{
struct timespec ts;
@@ -88,8 +72,6 @@ _thread_kern_sched(struct sigcontext * scp)
int add_to_prioq;
pthread_t old_thread_run;
- PTHREAD_TRACE(2);
-
/*
* Flag the pthread kernel as executing scheduler code
* to avoid a scheduler signal from interrupting this
@@ -257,23 +239,6 @@ _thread_kern_sched(struct sigcontext * scp)
PTHREAD_WORKQ_INSERT(curthread);
break;
}
-
- /*
- * Are there pending signals for this thread?
- *
- * This check has to be performed after the thread
- * has been placed in the queue(s) appropriate for
- * its state. The process of adding pending signals
- * can change a threads state, which in turn will
- * attempt to add or remove the thread from any
- * scheduling queue to which it belongs.
- */
-#ifdef notyet
- if (curthread->check_pending != 0) {
- curthread->check_pending = 0;
- _thread_sig_check_pending(curthread);
- }
-#endif
}
/*
@@ -502,18 +467,10 @@ _thread_kern_sched(struct sigcontext * scp)
/* Restore floating point state. */
_thread_machdep_restore_float_state(&curthread->_machdep);
- /*
- * Restore the new thread, saving current.
- */
+ /* Restore the new thread, saving current. */
_thread_machdep_switch(&curthread->_machdep,
&old_thread_run->_machdep);
-
- /*
- * Process any pending signals for the thread we
- * just switched to.
- */
_thread_kern_in_sched = 0;
- _dispatch_signals(scp);
/* run any installed switch-hooks */
if ((_sched_switch_hook != NULL) &&
@@ -529,6 +486,10 @@ _thread_kern_sched(struct sigcontext * scp)
PTHREAD_CANCEL_ASYNCHRONOUS) != 0))
pthread_testcancel();
+ /* dispatch any pending signals if possible */
+ if (curthread->sig_defer_count == 0)
+ _dispatch_signals(scp);
+
/* Check if a signal context was saved: */
if (curthread->sig_saved == 1) {
/* return to signal handler. This code
@@ -556,7 +517,6 @@ _thread_kern_sched_state(enum pthread_state state, char *fname, int lineno)
{
struct pthread *curthread = _get_curthread();
- PTHREAD_TRACE(3);
/*
* Flag the pthread kernel as executing scheduler code
* to avoid a scheduler signal from interrupting this
@@ -585,8 +545,6 @@ _thread_kern_sched_state_unlock(enum pthread_state state,
{
struct pthread *curthread = _get_curthread();
- PTHREAD_TRACE(4);
-
/*
* Flag the pthread kernel as executing scheduler code
* to avoid a scheduler signal from interrupting this
@@ -624,8 +582,6 @@ _thread_kern_poll(int wait_reqd)
struct timespec ts;
struct timeval tv;
- PTHREAD_TRACE(5);
-
/* Check if the caller wants to wait: */
if (wait_reqd == 0) {
timeout_ms = 0;
@@ -948,8 +904,6 @@ _thread_kern_set_timeout(const struct timespec * timeout)
struct timespec current_time;
struct timeval tv;
- PTHREAD_TRACE(6);
-
/* Reset the timeout flag for the running thread: */
curthread->timeout = 0;
@@ -990,8 +944,6 @@ _thread_kern_sig_defer(void)
{
struct pthread *curthread = _get_curthread();
- PTHREAD_TRACE(7);
-
/* Allow signal deferral to be recursive. */
curthread->sig_defer_count++;
}
@@ -1001,8 +953,6 @@ _thread_kern_sig_undefer(void)
{
struct pthread *curthread = _get_curthread();
- PTHREAD_TRACE(8);
-
/*
* Perform checks to yield only if we are about to undefer
* signals.
@@ -1049,8 +999,6 @@ _dequeue_signals(void)
char bufr[128];
int i, num;
- PTHREAD_TRACE(9);
-
/*
* Enter a loop to read and handle queued signals from the
* pthread kernel pipe:
@@ -1062,16 +1010,8 @@ _dequeue_signals(void)
* each byte is the signal number.
*/
for (i = 0; i < num; i++) {
- if ((int) bufr[i] == _SCHED_SIGNAL) {
- /*
- * Scheduling signals shouldn't ever be
- * queued; just ignore it for now.
- */
- }
- else {
- /* Handle this signal: */
- _thread_sig_process((int) bufr[i], NULL);
- }
+ if ((int) bufr[i] != _SCHED_SIGNAL)
+ _thread_sig_handle((int) bufr[i], NULL);
}
}
if ((num < 0) && (errno != EAGAIN)) {
@@ -1089,8 +1029,6 @@ _thread_run_switch_hook(pthread_t thread_out, pthread_t thread_in)
pthread_t tid_out = thread_out;
pthread_t tid_in = thread_in;
- PTHREAD_TRACE(10);
-
if ((tid_out != NULL) &&
(tid_out->flags & PTHREAD_FLAGS_PRIVATE) != 0)
tid_out = NULL;