more freebsd work
This commit is contained in:
parent
9cb22ba607
commit
d54ead7fb9
10 changed files with 118 additions and 40 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue