diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-17 09:38:06 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-17 12:38:18 -0600 |
commit | 47b2f4c4982fb5f063e9e83c524b2e63abaa58c4 (patch) | |
tree | f3f1727a36b79927e105415d650c53532489ba07 /coroutine.c | |
parent | a3c2e3bb9092f1d17671c22fd7bf5c0de9b61c3a (diff) |
wip
Diffstat (limited to 'coroutine.c')
-rw-r--r-- | coroutine.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/coroutine.c b/coroutine.c index 491dc67..13a747a 100644 --- a/coroutine.c +++ b/coroutine.c @@ -4,6 +4,7 @@ * SPDX-Licence-Identifier: AGPL-3.0-or-later */ +#include <stdio.h> #include <stdlib.h> /* for malloc(pico_malloc) and realloc(pico_malloc) */ #include "coroutine.h" @@ -13,9 +14,13 @@ _cr_entry_t *_coroutine_table = NULL; cid_t _cur_cid = 0; void coroutine_init(void) { - if (coroutine_table_len) + printf("coroutine_table_len = %u\n", (int)coroutine_table_len); + if (coroutine_table_len) { + printf("return\n"); return; + } coroutine_table_len = 1; + printf("coroutine_table_len = %u\n", (int)coroutine_table_len); _coroutine_table = malloc(sizeof _coroutine_table[0]); _coroutine_table[0] = (_cr_entry_t){ .fn = (cr_fn_t)0xDEAD, @@ -40,6 +45,7 @@ cid_t coroutine_add(cr_fn_t fn, void *stack) { .state = 0, .blocked = false, }; + printf("added coroutine %u\n", (int)cid); return cid; } @@ -51,8 +57,13 @@ void coroutine_task(void) { (_coroutine_table[(start+shift)%coroutine_table_len].fn == NULL || _coroutine_table[(start+shift)%coroutine_table_len].blocked); shift++) {} - if (shift == coroutine_table_len) + if (shift == coroutine_table_len) { + printf("idle\n"); return; + } _cur_cid = (start + shift) % coroutine_table_len; + printf("running %u\n", (int)_cur_cid); + if (_cur_cid == 0) + exit(1); _coroutine_table[_cur_cid].fn(_coroutine_table[_cur_cid].stack); } |