diff options
| author | Jason Evans <jasone@FreeBSD.org> | 2001-08-16 06:31:32 +0000 |
|---|---|---|
| committer | Jason Evans <jasone@FreeBSD.org> | 2001-08-16 06:31:32 +0000 |
| commit | 8588aeec8c491662c6795e9c934f89feb5b1442a (patch) | |
| tree | 58d56e8f03dd7d3a15b34ecf3a5680c7e056fa65 | |
| parent | d5499896947b8579868536fafa6cc704a6de7f4f (diff) | |
Notes
| -rw-r--r-- | lib/libc_r/uthread/pthread_private.h | 1 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_cancel.c | 16 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_join.c | 3 | ||||
| -rw-r--r-- | lib/libkse/thread/thr_cancel.c | 16 | ||||
| -rw-r--r-- | lib/libkse/thread/thr_join.c | 3 | ||||
| -rw-r--r-- | lib/libkse/thread/thr_private.h | 1 | ||||
| -rw-r--r-- | lib/libpthread/thread/thr_cancel.c | 16 | ||||
| -rw-r--r-- | lib/libpthread/thread/thr_join.c | 3 | ||||
| -rw-r--r-- | lib/libpthread/thread/thr_private.h | 1 |
9 files changed, 54 insertions, 6 deletions
diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h index 2bfac782d8873..cc3ec79baf57c 100644 --- a/lib/libc_r/uthread/pthread_private.h +++ b/lib/libc_r/uthread/pthread_private.h @@ -575,6 +575,7 @@ union pthread_wait_data { FILE *fp; struct pthread_poll_data *poll_data; spinlock_t *spinlock; + struct pthread *thread; }; /* diff --git a/lib/libc_r/uthread/uthread_cancel.c b/lib/libc_r/uthread/uthread_cancel.c index 2af3db6b2c1c0..7f40e3601e71b 100644 --- a/lib/libc_r/uthread/uthread_cancel.c +++ b/lib/libc_r/uthread/uthread_cancel.c @@ -64,9 +64,23 @@ _pthread_cancel(pthread_t pthread) break; case PS_JOIN: + /* + * Disconnect the thread from the joinee and + * detach: + */ + if (pthread->data.thread != NULL) { + pthread->data.thread->joiner = NULL; + pthread_detach((pthread_t) + pthread->data.thread); + } + pthread->cancelflags |= PTHREAD_CANCELLING; + PTHREAD_NEW_STATE(pthread, PS_RUNNING); + break; + case PS_SUSPENDED: if (pthread->suspended == SUSP_NO || pthread->suspended == SUSP_YES || + pthread->suspended == SUSP_JOIN || pthread->suspended == SUSP_NOWAIT) { /* * This thread isn't in any scheduling @@ -189,7 +203,6 @@ _pthread_testcancel(void) */ curthread->cancelflags &= ~PTHREAD_CANCELLING; _thread_exit_cleanup(); - pthread_detach((pthread_t)curthread); pthread_exit(PTHREAD_CANCELED); PANIC("cancel"); } @@ -226,7 +239,6 @@ finish_cancellation(void *arg) if ((curthread->cancelflags & PTHREAD_CANCEL_NEEDED) != 0) { curthread->cancelflags &= ~PTHREAD_CANCEL_NEEDED; _thread_exit_cleanup(); - pthread_detach((pthread_t)curthread); pthread_exit(PTHREAD_CANCELED); } } diff --git a/lib/libc_r/uthread/uthread_join.c b/lib/libc_r/uthread/uthread_join.c index 968c24cb90640..454c79a924f9f 100644 --- a/lib/libc_r/uthread/uthread_join.c +++ b/lib/libc_r/uthread/uthread_join.c @@ -121,6 +121,9 @@ _pthread_join(pthread_t pthread, void **thread_return) /* Set the running thread to be the joiner: */ pthread->joiner = curthread; + /* Keep track of which thread we're joining to: */ + curthread->data.thread = pthread; + /* Schedule the next thread: */ _thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__); diff --git a/lib/libkse/thread/thr_cancel.c b/lib/libkse/thread/thr_cancel.c index 2af3db6b2c1c0..7f40e3601e71b 100644 --- a/lib/libkse/thread/thr_cancel.c +++ b/lib/libkse/thread/thr_cancel.c @@ -64,9 +64,23 @@ _pthread_cancel(pthread_t pthread) break; case PS_JOIN: + /* + * Disconnect the thread from the joinee and + * detach: + */ + if (pthread->data.thread != NULL) { + pthread->data.thread->joiner = NULL; + pthread_detach((pthread_t) + pthread->data.thread); + } + pthread->cancelflags |= PTHREAD_CANCELLING; + PTHREAD_NEW_STATE(pthread, PS_RUNNING); + break; + case PS_SUSPENDED: if (pthread->suspended == SUSP_NO || pthread->suspended == SUSP_YES || + pthread->suspended == SUSP_JOIN || pthread->suspended == SUSP_NOWAIT) { /* * This thread isn't in any scheduling @@ -189,7 +203,6 @@ _pthread_testcancel(void) */ curthread->cancelflags &= ~PTHREAD_CANCELLING; _thread_exit_cleanup(); - pthread_detach((pthread_t)curthread); pthread_exit(PTHREAD_CANCELED); PANIC("cancel"); } @@ -226,7 +239,6 @@ finish_cancellation(void *arg) if ((curthread->cancelflags & PTHREAD_CANCEL_NEEDED) != 0) { curthread->cancelflags &= ~PTHREAD_CANCEL_NEEDED; _thread_exit_cleanup(); - pthread_detach((pthread_t)curthread); pthread_exit(PTHREAD_CANCELED); } } diff --git a/lib/libkse/thread/thr_join.c b/lib/libkse/thread/thr_join.c index 968c24cb90640..454c79a924f9f 100644 --- a/lib/libkse/thread/thr_join.c +++ b/lib/libkse/thread/thr_join.c @@ -121,6 +121,9 @@ _pthread_join(pthread_t pthread, void **thread_return) /* Set the running thread to be the joiner: */ pthread->joiner = curthread; + /* Keep track of which thread we're joining to: */ + curthread->data.thread = pthread; + /* Schedule the next thread: */ _thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__); diff --git a/lib/libkse/thread/thr_private.h b/lib/libkse/thread/thr_private.h index 2bfac782d8873..cc3ec79baf57c 100644 --- a/lib/libkse/thread/thr_private.h +++ b/lib/libkse/thread/thr_private.h @@ -575,6 +575,7 @@ union pthread_wait_data { FILE *fp; struct pthread_poll_data *poll_data; spinlock_t *spinlock; + struct pthread *thread; }; /* diff --git a/lib/libpthread/thread/thr_cancel.c b/lib/libpthread/thread/thr_cancel.c index 2af3db6b2c1c0..7f40e3601e71b 100644 --- a/lib/libpthread/thread/thr_cancel.c +++ b/lib/libpthread/thread/thr_cancel.c @@ -64,9 +64,23 @@ _pthread_cancel(pthread_t pthread) break; case PS_JOIN: + /* + * Disconnect the thread from the joinee and + * detach: + */ + if (pthread->data.thread != NULL) { + pthread->data.thread->joiner = NULL; + pthread_detach((pthread_t) + pthread->data.thread); + } + pthread->cancelflags |= PTHREAD_CANCELLING; + PTHREAD_NEW_STATE(pthread, PS_RUNNING); + break; + case PS_SUSPENDED: if (pthread->suspended == SUSP_NO || pthread->suspended == SUSP_YES || + pthread->suspended == SUSP_JOIN || pthread->suspended == SUSP_NOWAIT) { /* * This thread isn't in any scheduling @@ -189,7 +203,6 @@ _pthread_testcancel(void) */ curthread->cancelflags &= ~PTHREAD_CANCELLING; _thread_exit_cleanup(); - pthread_detach((pthread_t)curthread); pthread_exit(PTHREAD_CANCELED); PANIC("cancel"); } @@ -226,7 +239,6 @@ finish_cancellation(void *arg) if ((curthread->cancelflags & PTHREAD_CANCEL_NEEDED) != 0) { curthread->cancelflags &= ~PTHREAD_CANCEL_NEEDED; _thread_exit_cleanup(); - pthread_detach((pthread_t)curthread); pthread_exit(PTHREAD_CANCELED); } } diff --git a/lib/libpthread/thread/thr_join.c b/lib/libpthread/thread/thr_join.c index 968c24cb90640..454c79a924f9f 100644 --- a/lib/libpthread/thread/thr_join.c +++ b/lib/libpthread/thread/thr_join.c @@ -121,6 +121,9 @@ _pthread_join(pthread_t pthread, void **thread_return) /* Set the running thread to be the joiner: */ pthread->joiner = curthread; + /* Keep track of which thread we're joining to: */ + curthread->data.thread = pthread; + /* Schedule the next thread: */ _thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__); diff --git a/lib/libpthread/thread/thr_private.h b/lib/libpthread/thread/thr_private.h index 2bfac782d8873..cc3ec79baf57c 100644 --- a/lib/libpthread/thread/thr_private.h +++ b/lib/libpthread/thread/thr_private.h @@ -575,6 +575,7 @@ union pthread_wait_data { FILE *fp; struct pthread_poll_data *poll_data; spinlock_t *spinlock; + struct pthread *thread; }; /* |
