summaryrefslogtreecommitdiffstats
path: root/lib/libkse/thread/thr_exit.c
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2000-11-09 05:08:26 +0000
committerdeischen <deischen@FreeBSD.org>2000-11-09 05:08:26 +0000
commit69c0393f8e4b9bd522c1e9afe2f481e040dcbac3 (patch)
treea9d526e7ccca466ce303b1c6202f807942d274db /lib/libkse/thread/thr_exit.c
parente1d8dafb1c246b5ecfd3bf52b6e9ff947e171314 (diff)
downloadFreeBSD-src-69c0393f8e4b9bd522c1e9afe2f481e040dcbac3.zip
FreeBSD-src-69c0393f8e4b9bd522c1e9afe2f481e040dcbac3.tar.gz
Don't needlessly poll file descriptors when there are no
file descriptors needing to be polled (Doh!). Reported by Dan Nelson <dnelson@emsphone.com>. Don't install and start the scheduling timer until the first thread is created. This prevents the overhead of having a periodic scheduling signal in a single threaded program. Reported by Dan Nelson <dnelson@emsphone.com>. Allow builtin longjmps out of application installed signal handlers without the need perform any post-handler cleanup: o Change signal handling to save the threads interrupted context on the stack. The threads current context is now always stored in the same place (in the pthread). If and when a signal handler returns, the interrupted context is copied back to the storage area in the pthread. o Before calling invoking a signal handler for a thread, back the thread out of any internal waiting queues (mutex, CV, join, etc) to which it belongs. Rework uthread_info.c a bit to make it easier to change the format of a thread dump. Use an alternal signal stack for the thread library's signal handler. This allows us to fiddle with the main threads stack without fear of it being in use. Reviewed by: jasone
Diffstat (limited to 'lib/libkse/thread/thr_exit.c')
-rw-r--r--lib/libkse/thread/thr_exit.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/lib/libkse/thread/thr_exit.c b/lib/libkse/thread/thr_exit.c
index 7fbeb65..aef12fe 100644
--- a/lib/libkse/thread/thr_exit.c
+++ b/lib/libkse/thread/thr_exit.c
@@ -141,7 +141,7 @@ _thread_exit_cleanup(void)
void
pthread_exit(void *status)
{
- int frame;
+ pthread_t pthread;
/* Check if this thread is already in the process of exiting: */
if ((_thread_run->flags & PTHREAD_EXITING) != 0) {
@@ -159,7 +159,6 @@ pthread_exit(void *status)
while (_thread_run->cleanup != NULL) {
pthread_cleanup_pop(1);
}
-
if (_thread_run->attr.cleanup_attr != NULL) {
_thread_run->attr.cleanup_attr(_thread_run->attr.arg_attr);
}
@@ -175,25 +174,6 @@ pthread_exit(void *status)
_thread_run->poll_data.fds = NULL;
}
- if ((frame = _thread_run->sigframe_count) == 0)
- _thread_exit_finish();
- else {
- /*
- * Jump back and unwind the signal frames to gracefully
- * cleanup.
- */
- ___longjmp(*_thread_run->sigframes[frame]->sig_jb, 1);
- }
-
- /* This point should not be reached. */
- PANIC("Dead thread has resumed");
-}
-
-void
-_thread_exit_finish(void)
-{
- pthread_t pthread;
-
/*
* Lock the garbage collector mutex to ensure that the garbage
* collector is not using the dead thread list.
@@ -233,6 +213,16 @@ _thread_exit_finish(void)
* detach this thread:
*/
PTHREAD_NEW_STATE(pthread, PS_RUNNING);
+
+ /*
+ * Set the return value for the woken thread:
+ */
+ if ((_thread_run->attr.flags & PTHREAD_DETACHED) != 0)
+ pthread->error = ESRCH;
+ else {
+ pthread->ret = _thread_run->ret;
+ pthread->error = 0;
+ }
}
/* Remove this thread from the thread list: */
@@ -240,5 +230,8 @@ _thread_exit_finish(void)
/* This thread will never be re-scheduled. */
_thread_kern_sched_state(PS_DEAD, __FILE__, __LINE__);
+
+ /* This point should not be reached. */
+ PANIC("Dead thread has resumed");
}
#endif
OpenPOWER on IntegriCloud