From ca8d254d39e84cbe3374cbc76a5e21efae88e7a0 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 21 Nov 2024 23:57:23 -0700 Subject: libcr: Track coroutine names --- libcr/coroutine.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'libcr/coroutine.c') 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 /* for setjmp(), longjmp(), jmp_buf */ #include /* for uint8_t */ #include /* for aligned_alloc(), free() */ +#include /* for strncpy(), memset() */ #include @@ -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); -- cgit v1.2.3-2-g168b