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/>.
28 #include <valgrind/memcheck.h>
30 struct muth *current = NULL;
31 static ucontext_t mainctxt;
33 static void freemt(struct muth *muth)
37 #ifdef VALGRIND_STACK_DEREGISTER
38 VALGRIND_STACK_DEREGISTER(muth->vgid);
44 static void muboot(void)
50 muth->entry(muth, *muth->arglist);
52 swapcontext(&muth->ctxt, muth->last);
55 struct muth *mustart(void (*fn)(struct muth *muth, va_list args), ...)
57 struct muth *muth, *last;
61 getcontext(&muth->ctxt);
62 muth->ctxt.uc_link = &mainctxt;
63 muth->ctxt.uc_stack.ss_size = 65536;
64 muth->ctxt.uc_stack.ss_sp = muth->stack = smalloc(muth->ctxt.uc_stack.ss_size);
65 #ifdef VALGRIND_STACK_REGISTER
66 muth->vgid = VALGRIND_STACK_REGISTER(muth->stack, muth->stack + 65536);
70 muth->arglist = &args;
71 makecontext(&muth->ctxt, muboot, 0);
73 muth->last = &mainctxt;
75 muth->last = ¤t->ctxt;
78 swapcontext(muth->last, &muth->ctxt);
90 if((current == NULL) || (current->last == NULL))
94 swapcontext(¤t->ctxt, ret);
98 void resume(struct muth *muth, int ret)
102 if(muth->last != NULL)
105 muth->last = &mainctxt;
107 muth->last = ¤t->ctxt;
111 swapcontext(muth->last, ¤t->ctxt);