11#include "wasm/fiber.h" 
   12#include "wasm/asyncify.h" 
   14#ifdef RB_WASM_ENABLE_DEBUG_LOG 
   16# define RB_WASM_DEBUG_LOG(...) fprintf(stderr, __VA_ARGS__) 
   18# define RB_WASM_DEBUG_LOG(...) 
   24    fcp->asyncify_buf.top = &fcp->asyncify_buf.buffer[0];
 
   25    fcp->asyncify_buf.end = &fcp->asyncify_buf.buffer[WASM_FIBER_STACK_BUFFER_SIZE];
 
   26    fcp->is_rewinding = 
false;
 
   27    fcp->is_started = 
false;
 
   28    fcp->entry_point = func;
 
   31    RB_WASM_DEBUG_LOG(
"[%s] fcp->asyncify_buf %p\n", __func__, &fcp->asyncify_buf);
 
   39    RB_WASM_DEBUG_LOG(
"[%s] enter ofcp = %p fcp = %p\n", __func__, ofcp, fcp);
 
   40    if (ofcp->is_rewinding) {
 
   41        asyncify_stop_rewind();
 
   42        ofcp->is_rewinding = 
false;
 
   45    _rb_wasm_active_next_fiber = fcp;
 
   46    RB_WASM_DEBUG_LOG(
"[%s] start unwinding asyncify_buf = %p\n", __func__, &ofcp->asyncify_buf);
 
   47    asyncify_start_unwind(&ofcp->asyncify_buf);
 
   51rb_wasm_handle_fiber_unwind(
void (**new_fiber_entry)(
void *, 
void *),
 
   52                            void **arg0, 
void **arg1, 
bool *is_new_fiber_started)
 
   55    if (!_rb_wasm_active_next_fiber) {
 
   56        RB_WASM_DEBUG_LOG(
"[%s] no next fiber\n", __func__);
 
   57        *is_new_fiber_started = 
false;
 
   61    next_fiber = _rb_wasm_active_next_fiber;
 
   62    _rb_wasm_active_next_fiber = NULL;
 
   64    RB_WASM_DEBUG_LOG(
"[%s] next_fiber->asyncify_buf = %p\n", __func__, &next_fiber->asyncify_buf);
 
   66    *new_fiber_entry = next_fiber->entry_point;
 
   67    *arg0 = next_fiber->arg0;
 
   68    *arg1 = next_fiber->arg1;
 
   70    if (!next_fiber->is_started) {
 
   71        RB_WASM_DEBUG_LOG(
"[%s] new fiber started\n", __func__);
 
   73        next_fiber->is_started = 
true;
 
   74        *is_new_fiber_started = 
true;
 
   77        RB_WASM_DEBUG_LOG(
"[%s] resume a fiber\n", __func__);
 
   79        next_fiber->is_rewinding = 
true;
 
   80        *is_new_fiber_started = 
false;
 
   81        return &next_fiber->asyncify_buf;