summaryrefslogtreecommitdiff
path: root/libcr
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-26 20:09:17 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-26 20:09:17 -0700
commite7e0cff1960fca598e0ba01be2bb56b65cbb9e2b (patch)
tree1e2c607ae9980b47917effe4203b4448a1dd4c5f /libcr
parentd0e9e9c4a178fe396f3ba255bc440a15b107a097 (diff)
parent1aecc70750ee6ce9c96ebf3e6b4a7fb322ff8ca3 (diff)
Merge branch 'lukeshu/check-build'
Diffstat (limited to 'libcr')
-rw-r--r--libcr/coroutine.c38
-rw-r--r--libcr/tests/test_matrix/config.h2
2 files changed, 25 insertions, 15 deletions
diff --git a/libcr/coroutine.c b/libcr/coroutine.c
index 7278225..129f4da 100644
--- a/libcr/coroutine.c
+++ b/libcr/coroutine.c
@@ -46,6 +46,10 @@
#error config.h must define CONFIG_COROUTINE_GDB (bool)
#endif
+/* Enforce that CONFIG_COROUTINE_NUM is greater than 1, to work around
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118212 */
+static_assert(CONFIG_COROUTINE_NUM > 1);
+
/* Implementation *************************************************************/
#if CONFIG_COROUTINE_VALGRIND
@@ -386,7 +390,7 @@ struct coroutine {
#if CONFIG_COROUTINE_VALGRIND
unsigned stack_id;
#endif
- char name[CONFIG_COROUTINE_NAME_LEN];
+ [[gnu::nonstring]] char name[CONFIG_COROUTINE_NAME_LEN];
};
/* constants ******************************************************************/
@@ -522,10 +526,24 @@ static inline void assert_cid(cid_t cid) {
/* coroutine_add() ************************************************************/
+LM_NEVER_INLINE
+cid_t coroutine_allocate_cid(void) {
+ static cid_t last_created = 0;
+
+ size_t base = last_created;
+ for (size_t shift = 0; shift < CONFIG_COROUTINE_NUM; shift++) {
+ cid_t child = ((base + shift) % CONFIG_COROUTINE_NUM) + 1;
+ if (coroutine_table[child-1].state == CR_NONE) {
+ last_created = child;
+ return child;
+ }
+ }
+ return 0;
+}
+
cid_t coroutine_add_with_stack_size(size_t stack_size,
const char *name,
cr_fn_t fn, void *args) {
- static cid_t last_created = 0;
cid_t parent = coroutine_running;
if (parent)
@@ -540,21 +558,11 @@ cid_t coroutine_add_with_stack_size(size_t stack_size,
coroutine_initialized = true;
}
- cid_t child;
- {
- size_t base = last_created;
- for (size_t shift = 0; shift < CONFIG_COROUTINE_NUM; shift++) {
- child = ((base + shift) % CONFIG_COROUTINE_NUM) + 1;
- if (coroutine_table[child-1].state == CR_NONE)
- goto found;
- }
+ cid_t child = coroutine_allocate_cid();
+ if (!child)
return 0;
- found:
- }
debugf("...child=%zu", child);
- last_created = child;
-
if (name)
strncpy(coroutine_table[child-1].name, name, sizeof(coroutine_table[child-1].name));
else
@@ -753,6 +761,7 @@ cid_t cr_getcid(void) {
return coroutine_running;
}
+#ifndef NDEBUG
void cr_assert_in_coroutine(void) {
assert(!cr_plat_is_in_intrhandler());
assert_cid_state(coroutine_running, state == CR_RUNNING);
@@ -761,6 +770,7 @@ void cr_assert_in_coroutine(void) {
void cr_assert_in_intrhandler(void) {
assert(cr_plat_is_in_intrhandler());
}
+#endif
/* cr_cid_info() **************************************************************/
diff --git a/libcr/tests/test_matrix/config.h b/libcr/tests/test_matrix/config.h
index 9802f08..becfce0 100644
--- a/libcr/tests/test_matrix/config.h
+++ b/libcr/tests/test_matrix/config.h
@@ -9,6 +9,6 @@
#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (4*1024)
#define CONFIG_COROUTINE_NAME_LEN 16
-#define CONFIG_COROUTINE_NUM 1
+#define CONFIG_COROUTINE_NUM 2
#endif /* _CONFIG_H_ */