diff options
author | jake <jake@FreeBSD.org> | 2003-04-03 03:34:50 +0000 |
---|---|---|
committer | jake <jake@FreeBSD.org> | 2003-04-03 03:34:50 +0000 |
commit | 5b2b2811a19544037b626ef44e598691b3b2f525 (patch) | |
tree | d95f2bb910f0eebc71243aa5c4f13994c66da5ec | |
parent | 12c39a9461b4db1d8608dca0cb0cfc47ff8b234e (diff) | |
download | FreeBSD-src-5b2b2811a19544037b626ef44e598691b3b2f525.zip FreeBSD-src-5b2b2811a19544037b626ef44e598691b3b2f525.tar.gz |
- Pass a ucontext_t to _set_curthread. If non-NULL the new thread is set
as curthread in the new context, so that it will be set automatically when
the thread is switched to. This fixes a race where we'd run for a little
while with curthread unset in _thread_start.
Reviewed by: jeff
-rw-r--r-- | lib/libthr/arch/i386/i386/_setcurthread.c | 8 | ||||
-rw-r--r-- | lib/libthr/arch/sparc64/sparc64/_setcurthread.c | 7 | ||||
-rw-r--r-- | lib/libthr/thread/thr_create.c | 8 | ||||
-rw-r--r-- | lib/libthr/thread/thr_init.c | 2 | ||||
-rw-r--r-- | lib/libthr/thread/thr_private.h | 4 |
5 files changed, 18 insertions, 11 deletions
diff --git a/lib/libthr/arch/i386/i386/_setcurthread.c b/lib/libthr/arch/i386/i386/_setcurthread.c index 7eac3ba..29cd646 100644 --- a/lib/libthr/arch/i386/i386/_setcurthread.c +++ b/lib/libthr/arch/i386/i386/_setcurthread.c @@ -27,6 +27,7 @@ */ #include <sys/types.h> +#include <sys/ucontext.h> #include <stdio.h> @@ -66,7 +67,7 @@ _retire_thread(void *entry) } void * -_set_curthread(void *thr) +_set_curthread(ucontext_t *uc, void *thr) { union descriptor desc; void **ldt_entry; @@ -116,7 +117,10 @@ _set_curthread(void *thr) /* * Set up our gs with the index into the ldt for this entry. */ - _set_gs(LSEL(ldt_index, SEL_UPL)); + if (uc != NULL) + uc->uc_mcontext.mc_gs = LSEL(ldt_index, SEL_UPL); + else + _set_gs(LSEL(ldt_index, SEL_UPL)); return (ldt_entry); } diff --git a/lib/libthr/arch/sparc64/sparc64/_setcurthread.c b/lib/libthr/arch/sparc64/sparc64/_setcurthread.c index d37c177..4f1a303 100644 --- a/lib/libthr/arch/sparc64/sparc64/_setcurthread.c +++ b/lib/libthr/arch/sparc64/sparc64/_setcurthread.c @@ -48,9 +48,12 @@ _retire_thread(void *v) } void * -_set_curthread(struct pthread *thread) +_set_curthread(ucontext_t *uc, struct pthread *thread) { - _curthread = thread; + if (uc != NULL) + uc->uc_mcontext.mc_global[6] = (uint64_t)thread; + else + _curthread = thread; return (NULL); } diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c index 539a7c5..3ad7dc0 100644 --- a/lib/libthr/thread/thr_create.c +++ b/lib/libthr/thread/thr_create.c @@ -116,7 +116,8 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, getcontext(&new_thread->ctx); new_thread->ctx.uc_stack.ss_sp = new_thread->stack; new_thread->ctx.uc_stack.ss_size = pattr->stacksize_attr; - makecontext(&new_thread->ctx, _thread_start, 1, new_thread); + makecontext(&new_thread->ctx, _thread_start, 0); + new_thread->arch_id = _set_curthread(&new_thread->ctx, new_thread); /* Copy the thread attributes: */ memcpy(&new_thread->attr, pattr, sizeof(struct pthread_attr)); @@ -208,12 +209,11 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, } void -_thread_start(pthread_t thread) +_thread_start(void) { - thread->arch_id = _set_curthread(thread); /* Run the current thread's start routine with argument: */ - pthread_exit(thread->start_routine(thread->arg)); + pthread_exit(curthread->start_routine(curthread->arg)); /* This point should never be reached. */ PANIC("Thread has resumed after exit"); diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index 6a6fd45..1a0c648 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -219,7 +219,7 @@ _thread_init(void) PANIC("Cannot allocate memory for initial thread"); } _thread_initial = pthread; - pthread->arch_id = _set_curthread(pthread); + pthread->arch_id = _set_curthread(NULL, pthread); /* Zero the initial thread structure: */ memset(pthread, 0, sizeof(struct pthread)); diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index 7cc10e3..6399d21 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -686,7 +686,7 @@ char *ttyname_r(int, char *, size_t); void _cond_wait_backout(pthread_t); int _find_thread(pthread_t); pthread_t _get_curthread(void); -void *_set_curthread(struct pthread *); +void *_set_curthread(ucontext_t *, struct pthread *); void _retire_thread(void *arch_id); void *_thread_stack_alloc(size_t, size_t); void _thread_stack_free(void *, size_t, size_t); @@ -720,7 +720,7 @@ void _thread_dump_info(void); void _thread_init(void); void _thread_sig_wrapper(int sig, siginfo_t *info, ucontext_t *context); void _thread_printf(int fd, const char *, ...); -void _thread_start(pthread_t); +void _thread_start(void); void _thread_seterrno(pthread_t, int); pthread_addr_t _thread_gc(pthread_addr_t); void _thread_enter_cancellation_point(void); |