diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-18 00:53:51 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-18 00:53:51 -0600 |
commit | 52eb34af7be585c411a9a9ab39f0bea1d19e7d32 (patch) | |
tree | 27218b9838f6b76b138ae27ae1ed05ad0b8382ad | |
parent | 8e5d84d3724afd9278ac759213d7ea6eb0982e54 (diff) |
fix?
-rw-r--r-- | coroutine.c | 9 | ||||
-rw-r--r-- | coroutine.h | 14 | ||||
-rw-r--r-- | net9p.c | 9 | ||||
-rw-r--r-- | net9p.h | 6 |
4 files changed, 20 insertions, 18 deletions
diff --git a/coroutine.c b/coroutine.c index fe6f5be..9e0920d 100644 --- a/coroutine.c +++ b/coroutine.c @@ -95,10 +95,7 @@ cid_t coroutine_add(cr_fn_t fn, void *args) { if (!setjmp(coroutine_add_env)) { /* point=a */ /* run until cr_begin() */ call_with_stack(coroutine_table[child-1].stack + (STACK_GROWS_DOWNWARD ? coroutine_table[child-1].stack_size : 0), fn, args); - /* cr_begin() calls longjmp(point=a); if fn returns - * then that means it didn't call cr_begin(), which is - * wrong. */ - assert(false); + assert(false); /* should cr_begin() instead of returning */ } assert(coroutine_table[child-1].state == CR_RUNNABLE); assert(parent == 0 || coroutine_table[parent-1].state == CR_RUNNING); @@ -113,12 +110,12 @@ void coroutine_main(void) { if (coroutine_running == 1) ran = false; if (coroutine_table[coroutine_running-1].state == CR_RUNNABLE) { + printf("running %zu...\n", coroutine_running); ran = true; coroutine_table[coroutine_running-1].state = CR_RUNNING; if (!setjmp(coroutine_main_env)) { /* point=b */ longjmp(coroutine_table[coroutine_running-1].env, 1); /* jump to point=c */ - /* Consider returning to be the same as cr_exit(). */ - coroutine_table[coroutine_running-1].state = CR_NONE; + assert(false); /* should cr_exit() instead of returning */ } if (coroutine_table[coroutine_running-1].state == CR_NONE) { free(coroutine_table[coroutine_running-1].stack); diff --git a/coroutine.h b/coroutine.h index 273680d..fbaf000 100644 --- a/coroutine.h +++ b/coroutine.h @@ -13,6 +13,8 @@ /* typedefs *******************************************************************/ typedef size_t cid_t; /* 0=none; otherwise 1-indexed */ + +#define COROUTINE __attribute__ ((noreturn, no_split_stack)) void typedef void (*cr_fn_t)(void *args); /* managing coroutines ********************************************************/ @@ -23,12 +25,12 @@ void coroutine_main(void); /* inside of coroutines *******************************************************/ -bool cr_begin(void); -void cr_exit(void); -void cr_yield(void); -void cr_pause_and_yield(void); -void cr_unpause(cid_t); -#define cr_end() +__attribute__ ((no_split_stack)) bool cr_begin( void); +__attribute__ ((no_split_stack, noreturn)) void cr_exit(void); +__attribute__ ((no_split_stack)) void cr_yield(void); +__attribute__ ((no_split_stack)) void cr_pause_and_yield(void); +__attribute__ ((no_split_stack)) void cr_unpause(cid_t); +#define cr_end cr_exit cid_t cr_getcid(void); @@ -9,11 +9,10 @@ #include <arpa/inet.h> #include "net9p.h" -#include "coroutine.h" void net9p_listen_cr(void *_arg) { (void)_arg; - printf("listen initializng...\n"); + printf("listen initializing...\n"); cr_begin(); printf("listen running...\n"); @@ -37,6 +36,7 @@ void net9p_listen_cr(void *_arg) { int conn = 9; if (!coroutine_add(net9p_worker_cr, &conn)) error(1, 0, "coroutine_add(net9p_worker_cr, &%d)", conn); + printf("im back...\n"); for (;;) { cr_yield(); } @@ -46,10 +46,11 @@ void net9p_listen_cr(void *_arg) { void net9p_worker_cr(void *_arg) { int fd = *((int *)_arg); + printf("worker %zu initializing...\n", cr_getcid()); cr_begin(); - printf("worker %zu\n", cr_getcid()); - close(fd); + printf("worker %zu running...\n", cr_getcid()); + //close(fd); cr_end(); } @@ -1,7 +1,9 @@ #ifndef _NET9P_H_ #define _NET9P_H_ -void net9p_listen_cr(void *); -void net9p_worker_cr(void *); +#include "coroutine.h" + +COROUTINE net9p_listen_cr(void *); +COROUTINE net9p_worker_cr(void *); #endif /* _NET9P_H_ */ |