summaryrefslogtreecommitdiff
path: root/libcr/coroutine.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcr/coroutine.c')
-rw-r--r--libcr/coroutine.c12
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);