Files
plan9port/src/libthread/ucontext.c

50 lines
957 B
C
Raw Normal View History

2004-09-21 01:11:28 +00:00
#include "threadimpl.h"
2004-10-22 17:15:30 +00:00
static void
launcher(void (*f)(void*), void *arg)
{
f(arg);
threadexits(nil);
}
2004-09-21 01:11:28 +00:00
void
_threadinitstack(Thread *t, void (*f)(void*), void *arg)
{
sigset_t zero;
/* do a reasonable initialization */
memset(&t->context.uc, 0, sizeof t->context.uc);
2004-09-21 01:11:28 +00:00
sigemptyset(&zero);
sigprocmask(SIG_BLOCK, &zero, &t->context.uc.uc_sigmask);
2004-09-21 01:11:28 +00:00
/* call getcontext, because on Linux makecontext neglects floating point */
getcontext(&t->context.uc);
2004-09-21 01:11:28 +00:00
/* call makecontext to do the real work. */
/* leave a few words open on both ends */
t->context.uc.uc_stack.ss_sp = t->stk+8;
t->context.uc.uc_stack.ss_size = t->stksize-16;
2004-10-22 17:15:30 +00:00
makecontext(&t->context.uc, (void(*)())launcher, 2, f, arg);
2004-09-21 01:11:28 +00:00
}
void
_threadinswitch(int enter)
{
USED(enter);
}
void
_threadstacklimit(void *bottom, void *top)
{
USED(bottom);
USED(top);
}
void
_swaplabel(Label *old, Label *new)
{
if(swapcontext(&old->uc, &new->uc) < 0)
sysfatal("swapcontext: %r");
}