diff options
author | deischen <deischen@FreeBSD.org> | 2003-07-31 21:09:11 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2003-07-31 21:09:11 +0000 |
commit | db2a04e50dcbcd5e84ac32da20747b45b0689255 (patch) | |
tree | 7f63a6ba096a5d32eb86437fb59b82dbf3aa7433 /lib/libpthread/arch/i386/include | |
parent | 2ba1b34bc1b48fe1e27609d065378cc9b8229e75 (diff) | |
download | FreeBSD-src-db2a04e50dcbcd5e84ac32da20747b45b0689255.zip FreeBSD-src-db2a04e50dcbcd5e84ac32da20747b45b0689255.tar.gz |
Take the same approach for i386 as that for ia64 and amd64. Use
the userland version of [gs]etcontext to switch between a thread
and the UTS scheduler (and back again). This also fixes a bug
in i386 _thr_setcontext() which wasn't properly restoring the
context.
Reviewed by: davidxu
Diffstat (limited to 'lib/libpthread/arch/i386/include')
-rw-r--r-- | lib/libpthread/arch/i386/include/pthread_md.h | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/libpthread/arch/i386/include/pthread_md.h b/lib/libpthread/arch/i386/include/pthread_md.h index ad0dfd6..980680a 100644 --- a/lib/libpthread/arch/i386/include/pthread_md.h +++ b/lib/libpthread/arch/i386/include/pthread_md.h @@ -31,23 +31,14 @@ #ifndef _PTHREAD_MD_H_ #define _PTHREAD_MD_H_ -#include <setjmp.h> +#include <sys/kse.h> #include <ucontext.h> -extern int _thr_setcontext(ucontext_t *); -extern int _thr_getcontext(ucontext_t *); +extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *); +extern int _thr_getcontext(mcontext_t *); -/* - * These are needed to ensure an application doesn't attempt to jump - * between stacks of different threads. They return the stack of - * jmp_buf, sigjmp_buf, and ucontext respectively. - */ -#define GET_STACK_JB(jb) ((unsigned long)((jb)[0]._jb[2])) -#define GET_STACK_SJB(sjb) ((unsigned long)((sjb)[0]._sjb[2])) -#define GET_STACK_UC(ucp) ((unsigned long)((ucp)->uc_mcontext.mc_esp)) - -#define THR_GETCONTEXT(ucp) _thr_getcontext(ucp) -#define THR_SETCONTEXT(ucp) _thr_setcontext(ucp) +#define THR_GETCONTEXT(ucp) _thr_getcontext(&(ucp)->uc_mcontext); +#define THR_SETCONTEXT(ucp) _thr_setcontext(&(ucp)->uc_mcontext, NULL, NULL); #define THR_ALIGNBYTES 15 #define THR_ALIGN(td) (((unsigned)(td) + THR_ALIGNBYTES) & ~THR_ALIGNBYTES) @@ -63,4 +54,32 @@ struct ksd { long size; }; +extern void _i386_enter_uts(struct kse_mailbox *, kse_func_t, void *, long); + +static __inline int +_thread_enter_uts(struct kse_thr_mailbox *tmbx, struct kse_mailbox *kmbx) +{ + int ret; + + ret = _thr_getcontext(&tmbx->tm_context.uc_mcontext); + if (ret == 0) { + _i386_enter_uts(kmbx, kmbx->km_func, + kmbx->km_stack.ss_sp, kmbx->km_stack.ss_size); + /* We should not reach here. */ + return (-1); + } + else if (ret < 0) + return (-1); + return (0); +} + +static __inline int +_thread_switch(struct kse_thr_mailbox *tmbx, struct kse_thr_mailbox **loc) +{ + _thr_setcontext(&tmbx->tm_context.uc_mcontext, + (intptr_t)tmbx, (intptr_t *)loc); + /* We should not reach here. */ + return (-1); +} + #endif |