diff options
Diffstat (limited to 'libcr/coroutine.c')
-rw-r--r-- | libcr/coroutine.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libcr/coroutine.c b/libcr/coroutine.c index fe2183e..df9cad3 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -309,7 +309,7 @@ static jmp_buf coroutine_main_env; * * - exactly 0 or 1 coroutines have state CR_INITIALIZING * - exactly 0 or 1 coroutines have state CR_RUNNING - * - if coroutine_running is not zero, then + * - if coroutine_running is non-zero, then * coroutine_table[coroutine_running-1] is the currently-running * coroutine * - the coroutine_running coroutine either has state CR_RUNNING or @@ -319,6 +319,8 @@ static jmp_buf coroutine_main_env; * in the middle of coroutine_add(), it coroutine_running points at * the CR_INITIALIZING child coroutine, while leaving the parent * coroutine as CR_RUNNING. + * - a coroutine has state CR_RUNNABLE if and only if it is is in the + * coroutine_ringbuf queue. */ static struct coroutine coroutine_table[CONFIG_COROUTINE_NUM] = {0}; @@ -450,7 +452,6 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, cr_fn_t fn, void *args) { assert(false); /* should cr_begin() instead of returning */ } assert_cid_state(child, state == CR_RUNNABLE); - coroutine_ringbuf_push(child); if (parent) assert_cid_state(parent, state == CR_RUNNING); coroutine_running = parent; @@ -499,6 +500,7 @@ void cr_begin(void) { assert_cid_state(coroutine_running, state == CR_INITIALIZING); coroutine_table[coroutine_running-1].state = CR_RUNNABLE; + coroutine_ringbuf_push(coroutine_running); coroutine_table[coroutine_running-1].sp = cr_plat_get_sp(); if (!cr_plat_setjmp(coroutine_table[coroutine_running-1].env)) /* point=c1 */ cr_plat_longjmp(coroutine_add_env, 1); /* jump to point=a */ @@ -534,6 +536,7 @@ void cr_yield(void) { cr_disable_interrupts(); coroutine_table[coroutine_running-1].state = CR_RUNNABLE; + coroutine_ringbuf_push(coroutine_running); _cr_yield(); cr_enable_interrupts(); } |