1#ifndef COROUTINE_ASYNCIFY_CONTEXT_H
2#define COROUTINE_ASYNCIFY_CONTEXT_H
16#include "wasm/asyncify.h"
17#include "wasm/machine.h"
18#include "wasm/fiber.h"
20#define COROUTINE void __attribute__((__noreturn__))
22static const int ASYNCIFY_CORO_DEBUG = 0;
37COROUTINE coroutine_trampoline(
void * _start,
void * _context);
41 if (ASYNCIFY_CORO_DEBUG) fprintf(stderr,
"[%s] entry (context = %p)\n", __func__, context);
43 rb_wasm_init_context(&context->fc, NULL, NULL, NULL);
45 context->fc.is_started =
true;
48static inline void coroutine_initialize(
struct coroutine_context *context, coroutine_start start,
void *stack,
size_t size)
50 if (ASYNCIFY_CORO_DEBUG) fprintf(stderr,
"[%s] entry (context = %p, stack = %p ... %p)\n", __func__, context, stack, (
char *)stack + size);
51 rb_wasm_init_context(&context->fc, coroutine_trampoline, start, context);
53 context->current_sp = (
char *)stack + size;
54 context->stack_base = stack;
60 if (ASYNCIFY_CORO_DEBUG) fprintf(stderr,
"[%s] entry (current = %p, target = %p)\n", __func__, current, target);
63 target->from = current;
64 if (ASYNCIFY_CORO_DEBUG) fprintf(stderr,
"[%s] current->current_sp = %p -> %p\n", __func__, current->current_sp, rb_wasm_get_stack_pointer());
66 current->current_sp = rb_wasm_get_stack_pointer();
70 rb_wasm_swapcontext(¤t->fc, &target->fc);
74 rb_wasm_set_stack_pointer(current->current_sp);
76 target->from = previous;
83 if (ASYNCIFY_CORO_DEBUG) fprintf(stderr,
"[%s] entry (context = %p)\n", __func__, context);
84 context->stack_base = NULL;