diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-21 23:57:23 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-23 13:56:51 -0700 |
commit | ca8d254d39e84cbe3374cbc76a5e21efae88e7a0 (patch) | |
tree | 30ae0f4888767bfd4b4b6d54cba3aade95371642 /libcr/coroutine.c | |
parent | 60230d7862a9a87b4ef5531d0a549172335a2e3f (diff) |
libcr: Track coroutine names
Diffstat (limited to 'libcr/coroutine.c')
-rw-r--r-- | libcr/coroutine.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/libcr/coroutine.c b/libcr/coroutine.c index 9cadc55..45dcb39 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -7,6 +7,7 @@ #include <setjmp.h> /* for setjmp(), longjmp(), jmp_buf */ #include <stdint.h> /* for uint8_t */ #include <stdlib.h> /* for aligned_alloc(), free() */ +#include <string.h> /* for strncpy(), memset() */ #include <libmisc/assert.h> @@ -23,6 +24,9 @@ #ifndef CONFIG_COROUTINE_DEFAULT_STACK_SIZE #error config.h must define CONFIG_COROUTINE_DEFAULT_STACK_SIZE #endif +#ifndef CONFIG_COROUTINE_NAME_LEN + #error config.h must define CONFIG_COROUTINE_NAME_LEN +#endif #ifndef CONFIG_COROUTINE_NUM #error config.h must define CONFIG_COROUTINE_NUM #endif @@ -365,6 +369,7 @@ struct coroutine { #if CONFIG_COROUTINE_VALGRIND unsigned stack_id; #endif + char name[CONFIG_COROUTINE_NAME_LEN]; }; /* constants ******************************************************************/ @@ -474,7 +479,7 @@ static inline void assert_cid(cid_t cid) { /* coroutine_add() ************************************************************/ cid_t coroutine_add_with_stack_size(size_t stack_size, - const char [[gnu::unused]] *name, + const char *name, cr_fn_t fn, void *args) { static cid_t last_created = 0; cid_t parent = coroutine_running; @@ -501,6 +506,11 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, last_created = child; + if (name) + strncpy(coroutine_table[child-1].name, name, sizeof(coroutine_table[child-1].name)); + else + memset(coroutine_table[child-1].name, 0, sizeof(coroutine_table[child-1].name)); + coroutine_table[child-1].stack_size = stack_size; coroutine_table[child-1].stack = aligned_alloc(CR_PLAT_STACK_ALIGNMENT, stack_size); |