Lines Matching +full:- +full:- +full:with +full:- +full:coroutine

2  * sigaltstack coroutine initialization code
8 ** Copyright (c) 1999-2006 Ralf S. Engelschall <rse@engelschall.com>
21 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
33 #error "SafeStack is not compatible with code run in alternate signal stacks"
37 Coroutine base;
44 * Per-thread coroutine bookkeeping
47 /** Currently executing coroutine */
48 Coroutine *current;
50 /** The default coroutine */
67 s->current = &s->leader.base; in coroutine_get_thread_state()
92 * This is what starts the coroutine, is called from the trampoline
96 static void coroutine_bootstrap(CoroutineSigAltStack *self, Coroutine *co) in coroutine_bootstrap()
99 if (!sigsetjmp(self->env, 0)) { in coroutine_bootstrap()
100 siglongjmp(*(sigjmp_buf *)co->entry_arg, 1); in coroutine_bootstrap()
104 co->entry(co->entry_arg); in coroutine_bootstrap()
105 qemu_coroutine_switch(co, co->caller, COROUTINE_TERMINATE); in coroutine_bootstrap()
110 * This is used as the signal handler. This is called with the brand new stack
117 Coroutine *co; in coroutine_trampoline()
122 self = coTS->tr_handler; in coroutine_trampoline()
123 coTS->tr_called = 1; in coroutine_trampoline()
124 co = &self->base; in coroutine_trampoline()
131 if (!sigsetjmp(coTS->tr_reenter, 0)) { in coroutine_trampoline()
139 * the auto variables (which have to be auto-variables in coroutine_trampoline()
140 * because the start of the thread happens later). Else with in coroutine_trampoline()
148 Coroutine *qemu_coroutine_new(void) in qemu_coroutine_new()
161 /* The way to manipulate stack is with the sigaltstack function. We in qemu_coroutine_new()
162 * prepare a stack, with it delivering a signal to ourselves and then in qemu_coroutine_new()
164 * This has been done keeping coroutine-ucontext as a model and with the in qemu_coroutine_new()
165 * pth ideas (GNU Portable Threads). See coroutine-ucontext for the basics in qemu_coroutine_new()
171 co->stack_size = COROUTINE_STACK_SIZE; in qemu_coroutine_new()
172 co->stack = qemu_alloc_stack(&co->stack_size); in qemu_coroutine_new()
173 co->base.entry_arg = &old_env; /* stash away our jmp_buf */ in qemu_coroutine_new()
176 coTS->tr_handler = co; in qemu_coroutine_new()
191 * sigaction() is a process-global operation. We must not run in qemu_coroutine_new()
202 ss.ss_sp = co->stack; in qemu_coroutine_new()
203 ss.ss_size = co->stack_size; in qemu_coroutine_new()
212 * was performed. Be careful here with race conditions. The in qemu_coroutine_new()
216 coTS->tr_called = 0; in qemu_coroutine_new()
220 while (!coTS->tr_called) { in qemu_coroutine_new()
250 * redundant ping-pong pointer arithmetic is necessary to avoid in qemu_coroutine_new()
251 * type-conversion warnings related to the `volatile' qualifier and in qemu_coroutine_new()
255 siglongjmp(coTS->tr_reenter, 1); in qemu_coroutine_new()
262 return &co->base; in qemu_coroutine_new()
265 void qemu_coroutine_delete(Coroutine *co_) in qemu_coroutine_delete()
269 qemu_free_stack(co->stack, co->stack_size); in qemu_coroutine_delete()
273 CoroutineAction qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, in qemu_coroutine_switch()
281 s->current = to_; in qemu_coroutine_switch()
283 ret = sigsetjmp(from->env, 0); in qemu_coroutine_switch()
285 siglongjmp(to->env, action); in qemu_coroutine_switch()
290 Coroutine *qemu_coroutine_self(void) in qemu_coroutine_self()
294 return s->current; in qemu_coroutine_self()
301 return s && s->current->caller; in qemu_in_coroutine()