diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-19 20:09:37 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-19 20:10:13 -0600 |
commit | 6c4af47ed66ddcc521d7fb72e116f9ca681116cc (patch) | |
tree | 60dbb86f69cb58da3089b999031d96443a07cf85 /coroutine.c | |
parent | a9a35f9d3b19724640fcb0b0cec057f95c8c6328 (diff) |
coroutine.c: debug logging
Diffstat (limited to 'coroutine.c')
-rw-r--r-- | coroutine.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/coroutine.c b/coroutine.c index 01418bd..fbcb355 100644 --- a/coroutine.c +++ b/coroutine.c @@ -16,6 +16,7 @@ #define COROUTINE_NUM 5 #define COROUTINE_MEASURE_STACK 1 +#define COROUTINE_DEBUG 1 /* Implementation *************************************************************/ @@ -104,6 +105,12 @@ * and a few bytes. */ +#if COROUTINE_DEBUG +# define debugf(...) printf("dbg: " __VA_ARGS__) +#else +# define debugf(...) +#endif + static jmp_buf coroutine_add_env; static jmp_buf coroutine_main_env; @@ -190,6 +197,7 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, cr_fn_t fn, void *args) { static cid_t last_created = 0; assert(coroutine_running == 0 || coroutine_table[coroutine_running-1].state == CR_RUNNING); + debugf("coroutine_add_with_stack_size(%zu, %#p, %#p)...\n", stack_size, fn, args); cid_t child; { @@ -221,16 +229,19 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, cr_fn_t fn, void *args) { assert(parent == 0 || coroutine_table[parent-1].state == CR_RUNNING); coroutine_running = parent; + debugf("coroutine_add_with_stack_size => %zu\n", child); return child; } void coroutine_main(void) { + debugf("coroutine_main()\n"); bool ran; for (coroutine_running = 1;; coroutine_running = (coroutine_running%COROUTINE_NUM)+1) { if (coroutine_running == 1) ran = false; struct coroutine *cr = &coroutine_table[coroutine_running-1]; if (cr->state == CR_RUNNABLE) { + debugf("running cid=%zu...\n", coroutine_running); ran = true; cr->state = CR_RUNNING; if (!setjmp(coroutine_main_env)) { /* point=b */ @@ -264,6 +275,7 @@ bool cr_begin(void) { static inline __attribute__ ((no_split_stack)) void _cr_transition(enum coroutine_state state) { assert(coroutine_running && coroutine_table[coroutine_running-1].state == CR_RUNNING); + debugf("_cr_transition cid=%zu %i->%i\n", coroutine_running, coroutine_table[coroutine_running-1].state, state); coroutine_table[coroutine_running-1].state = state; if (!setjmp(coroutine_table[coroutine_running-1].env)) /* point=c2 */ longjmp(coroutine_main_env, 1); /* jump to point=b */ @@ -280,6 +292,7 @@ void cr_exit(void) { void cr_unpause(cid_t cid) { assert(cid && coroutine_table[cid-1].state == CR_PAUSED); + debugf("cr_unpause(%zu)\n", cid); coroutine_table[cid-1].state = CR_RUNNABLE; } |