Skip to content

Commit

Permalink
Refactor most of coro_allocate into grow_stack
Browse files Browse the repository at this point in the history
  • Loading branch information
danluu committed Mar 21, 2013
1 parent 55cd561 commit 16ff0bf
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions coroutines.c
Expand Up @@ -68,7 +68,9 @@ static void grow_stack(int n, int num_coros) {

grow_stack(n + 1, num_coros);
} else {
// how does spawn/fork work?
if (n == 0) {
return; //came from coro_allocate; return back there
}
while(1) {
assert(spawned_fun);
coro_callback f = spawned_fun;
Expand All @@ -90,16 +92,5 @@ void coro_allocate(int num_coros) {
used_pids[0] = 1;
coro_pid = 0;

if (!setjmp(bufs[0])) {
// we only need the extra space here if we're going to
// call functions from coro_allocate
char *big_array;
big_array = alloca(STACK_SIZE);
asm volatile("" :: "m" (big_array));

grow_stack(1, num_coros);
assert(0);
} else {
return;
}
grow_stack(0, num_coros);
}

0 comments on commit 16ff0bf

Please sign in to comment.