From 47b2f4c4982fb5f063e9e83c524b2e63abaa58c4 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 17 Sep 2024 09:38:06 -0600 Subject: wip --- coroutine.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'coroutine.c') 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 #include /* 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); } -- cgit v1.2.3-2-g168b