diff options
Diffstat (limited to 'src/libthread/FreeBSD.c')
-rw-r--r-- | src/libthread/FreeBSD.c | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/src/libthread/FreeBSD.c b/src/libthread/FreeBSD.c index 77c4869a..0fdb54b9 100644 --- a/src/libthread/FreeBSD.c +++ b/src/libthread/FreeBSD.c @@ -1,11 +1,3 @@ -#include "u.h" -#include <errno.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <sched.h> -#include <signal.h> -#include "libc.h" -#include "thread.h" #include "threadimpl.h" extern int __isthreaded; @@ -70,7 +62,6 @@ _spinlock(spinlock_t *lk) { lock((Lock*)&lk->access_lock); } - __isthreaded = 1; /* * sleep and wakeup @@ -351,6 +342,46 @@ _threadsetproc(Proc *p) void _pthreadinit(void) { + __isthreaded = 1; signal(SIGUSR2, sigusr2handler); } +/* + * FreeBSD 4 and earlier needs the context functions. + */ +void +makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) +{ + int *sp; + + sp = (int*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/4; + sp -= argc; + memmove(sp, &argc+1, argc*sizeof(int)); + *--sp = 0; /* return address */ + ucp->uc_mcontext.mc_eip = (long)func; + ucp->uc_mcontext.mc_esp = (int)sp; +} + +extern int getmcontext(mcontext_t*); +extern int setmcontext(mcontext_t*); + +int +getcontext(ucontext_t *uc) +{ + return getmcontext(&uc->uc_mcontext); +} + +void +setcontext(ucontext_t *uc) +{ + setmcontext(&uc->uc_mcontext); +} + +int +swapcontext(ucontext_t *oucp, ucontext_t *ucp) +{ + if(getcontext(oucp) == 0) + setcontext(ucp); + return 0; +} + |