summaryrefslogtreecommitdiff
path: root/libcr/coroutine.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-07 23:45:09 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-08 08:27:23 -0700
commitc4106766ecc2ebcca66d3d5b8408768b36a31122 (patch)
tree4a8a6f5de3abad94ff78c7577a0912bcb37d7e1e /libcr/coroutine.c
parentca4de2716c6fa4772228e8e8e051ef09c69907e2 (diff)
libcr: Add cr_{set,long}jmp wrappers around the cr_plat_ variants
Diffstat (limited to 'libcr/coroutine.c')
-rw-r--r--libcr/coroutine.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/libcr/coroutine.c b/libcr/coroutine.c
index 996262e..c446276 100644
--- a/libcr/coroutine.c
+++ b/libcr/coroutine.c
@@ -471,6 +471,9 @@ static inline cid_t coroutine_ringbuf_pop(void) {
return coroutine_ringbuf.buf[coroutine_ringbuf.tail++ % ARRAY_LEN(coroutine_ringbuf.buf)];
}
+#define cr_setjmp(env) cr_plat_setjmp(env)
+#define cr_longjmp(env) cr_plat_longjmp(env, 1)
+
static inline void assert_cid(cid_t cid) {
assert(cid > 0);
assert(cid <= CONFIG_COROUTINE_NUM);
@@ -547,7 +550,7 @@ cid_t coroutine_add_with_stack_size(size_t stack_size,
coroutine_running = child;
coroutine_table[child-1].state = CR_INITIALIZING;
coroutine_cnt++;
- if (!cr_plat_setjmp(&coroutine_add_env)) { /* point=a */
+ if (!cr_setjmp(&coroutine_add_env)) { /* point=a */
void *stack_base = coroutine_table[child-1].stack
#if CR_PLAT_STACK_GROWS_DOWNWARD
+ stack_size
@@ -596,10 +599,10 @@ void coroutine_main(void) {
cr_plat_wait_for_interrupt();
}
- if (!cr_plat_setjmp(&coroutine_main_env)) { /* point=b */
+ if (!cr_setjmp(&coroutine_main_env)) { /* point=b */
coroutine_running = next;
coroutine_table[coroutine_running-1].state = CR_RUNNING;
- cr_plat_longjmp(&coroutine_table[coroutine_running-1].env, 1); /* jump to point=c */
+ cr_longjmp(&coroutine_table[coroutine_running-1].env); /* jump to point=c */
}
/* This is where we jump to from cr_exit(), and from
* nowhere else. */
@@ -623,8 +626,8 @@ void cr_begin(void) {
bool saved = cr_save_and_disable_interrupts();
coroutine_table[coroutine_running-1].state = CR_RUNNABLE;
coroutine_ringbuf_push(coroutine_running);
- if (!cr_plat_setjmp(&coroutine_table[coroutine_running-1].env)) /* point=c1 */
- cr_plat_longjmp(&coroutine_add_env, 1); /* jump to point=a */
+ if (!cr_setjmp(&coroutine_table[coroutine_running-1].env)) /* point=c1 */
+ cr_longjmp(&coroutine_add_env); /* jump to point=a */
cr_restore_interrupts(saved);
}
@@ -641,10 +644,10 @@ static inline void _cr_yield() {
return;
}
- if (!cr_plat_setjmp(&coroutine_table[coroutine_running-1].env)) { /* point=c2 */
+ if (!cr_setjmp(&coroutine_table[coroutine_running-1].env)) { /* point=c2 */
coroutine_running = next;
coroutine_table[coroutine_running-1].state = CR_RUNNING;
- cr_plat_longjmp(&coroutine_table[coroutine_running-1].env, 1); /* jump to point=c */
+ cr_longjmp(&coroutine_table[coroutine_running-1].env); /* jump to point=c */
}
}
@@ -678,7 +681,7 @@ void cr_pause_and_yield(void) {
(void)cr_save_and_disable_interrupts();
coroutine_table[coroutine_running-1].state = CR_NONE;
- cr_plat_longjmp(&coroutine_main_env, 1); /* jump to point=b */
+ cr_longjmp(&coroutine_main_env); /* jump to point=b */
}
static void _cr_unpause(cid_t cid) {