summaryrefslogtreecommitdiff
path: root/libcr
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-21 10:34:00 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-21 10:34:00 -0700
commit19a41387633e53d64d8a0ae69f3d3d3e35641c8d (patch)
treea89dead6dd34f95b3e644edeb02fe1ca70a28784 /libcr
parent4ba0b95dc825a83748b7cb2aa528411026d5bada (diff)
parent5dab625d981e0039a5d874f5d8a6f795472785bc (diff)
Merge branch 'lukeshu/misc'
Diffstat (limited to 'libcr')
-rw-r--r--libcr/coroutine.c9
-rw-r--r--libcr/include/libcr/coroutine.h16
-rw-r--r--libcr/tests/test_matrix/config.h2
3 files changed, 17 insertions, 10 deletions
diff --git a/libcr/coroutine.c b/libcr/coroutine.c
index c6eeb43..33e8141 100644
--- a/libcr/coroutine.c
+++ b/libcr/coroutine.c
@@ -21,9 +21,6 @@
#include "config.h"
-#ifndef CONFIG_COROUTINE_DEFAULT_STACK_SIZE
- #error config.h must define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (non-negative integer)
-#endif
#ifndef CONFIG_COROUTINE_NAME_LEN
#error config.h must define CONFIG_COROUTINE_NAME_LEN (non-negative integer)
#endif
@@ -630,11 +627,6 @@ cid_t coroutine_add_with_stack_size(size_t stack_size,
return child;
}
-cid_t coroutine_add(const char *name, cr_fn_t fn, void *args) {
- return coroutine_add_with_stack_size(
- CONFIG_COROUTINE_DEFAULT_STACK_SIZE, name, fn, args);
-}
-
/* coroutine_main() ***********************************************************/
void coroutine_main(void) {
@@ -676,6 +668,7 @@ void coroutine_main(void) {
coroutine_table[coroutine_running-1] = (struct coroutine){0};
coroutine_cnt--;
}
+ coroutine_running = 0;
cr_restore_interrupts(saved);
}
diff --git a/libcr/include/libcr/coroutine.h b/libcr/include/libcr/coroutine.h
index 756352e..2505782 100644
--- a/libcr/include/libcr/coroutine.h
+++ b/libcr/include/libcr/coroutine.h
@@ -29,8 +29,14 @@
#include <stddef.h> /* for size_t */
#include <stdbool.h> /* for bool */
+/* Configuration **************************************************************/
+
#include "config.h"
+#ifndef CONFIG_COROUTINE_MEASURE_STACK
+ #error config.h must define CONFIG_COROUTINE_MEASURE_STACK (bool)
+#endif
+
/* typedefs *******************************************************************/
/**
@@ -91,8 +97,16 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, const char *name, cr_fn_t
/**
* Like coroutine_add_with_stack_size(), but uses a default stack size so
* you don't need to think about it.
+ *
+ * Either define CONFIG_COROUTINE_STACK_SIZE_DEFAULT to use for all
+ * coroutines, or CONFIG_COROUTINE_STACK_SIZE_{fn} for each COROUTINE
+ * function.
*/
-cid_t coroutine_add(const char *name, cr_fn_t fn, void *args);
+#ifdef CONFIG_COROUTINE_STACK_SIZE_DEFAULT
+#define coroutine_add(name, fn, args) coroutine_add_with_stack_size(CONFIG_COROUTINE_STACK_SIZE_DEFAULT, name, fn, args)
+#else
+#define coroutine_add(name, fn, args) coroutine_add_with_stack_size(CONFIG_COROUTINE_STACK_SIZE_##fn, name, fn, args)
+#endif
/**
* The main scheduler loop. Returns if all coroutines exit.
diff --git a/libcr/tests/test_matrix/config.h b/libcr/tests/test_matrix/config.h
index becfce0..83892df 100644
--- a/libcr/tests/test_matrix/config.h
+++ b/libcr/tests/test_matrix/config.h
@@ -7,7 +7,7 @@
#ifndef _CONFIG_H_
#define _CONFIG_H_
-#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (4*1024)
+#define CONFIG_COROUTINE_STACK_SIZE_DEFAULT (4*1024)
#define CONFIG_COROUTINE_NAME_LEN 16
#define CONFIG_COROUTINE_NUM 2