2 ashd - A Sane HTTP Daemon
3 Copyright (C) 2008 Fredrik Tolf <fredrik@dolda2000.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include <valgrind/memcheck.h>
33 struct muth *current = NULL;
34 static ucontext_t mainctxt;
36 static void freemt(struct muth *muth)
40 #ifdef VALGRIND_STACK_DEREGISTER
41 VALGRIND_STACK_DEREGISTER(muth->vgid);
47 static void muboot(void)
53 muth->entry(muth, *muth->arglist);
55 swapcontext(&muth->ctxt, muth->last);
58 struct muth *mustart(void (*fn)(struct muth *muth, va_list args), ...)
60 struct muth *muth, *last;
64 getcontext(&muth->ctxt);
65 muth->ctxt.uc_link = &mainctxt;
66 muth->ctxt.uc_stack.ss_size = 65536;
67 muth->ctxt.uc_stack.ss_sp = muth->stack = smalloc(muth->ctxt.uc_stack.ss_size);
68 #ifdef VALGRIND_STACK_REGISTER
69 muth->vgid = VALGRIND_STACK_REGISTER(muth->stack, muth->stack + 65536);
73 muth->arglist = &args;
74 makecontext(&muth->ctxt, muboot, 0);
76 muth->last = &mainctxt;
78 muth->last = ¤t->ctxt;
81 swapcontext(muth->last, &muth->ctxt);
93 if((current == NULL) || (current->last == NULL))
97 swapcontext(¤t->ctxt, ret);
101 void resume(struct muth *muth, int ret)
105 if(muth->last != NULL)
108 muth->last = &mainctxt;
110 muth->last = ¤t->ctxt;
114 swapcontext(muth->last, ¤t->ctxt);