diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-01-06 14:16:56 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-01-06 14:16:56 +0900 |
| commit | ca3a6156bf0d15031ad946a67e9a88b4fb288d38 (patch) | |
| tree | bc8b9d044704dd79e6f67e312457d9568f127895 /src | |
| parent | 4585c360e4e2548c143042d45c7f5bf1dfc5fb9e (diff) | |
| download | mruby-ca3a6156bf0d15031ad946a67e9a88b4fb288d38.tar.gz mruby-ca3a6156bf0d15031ad946a67e9a88b4fb288d38.zip | |
Allow context switch from C using `mrb_fiber_resume()`.
But you still cannot cross C function boundary.
Diffstat (limited to 'src')
| -rw-r--r-- | src/vm.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -2074,7 +2074,7 @@ RETRY_TRY_BLOCK: regs[irep->nlocals] = v; goto CHECKPOINT_LABEL_MAKE(RBREAK_TAG_STOP); } - if (c->prev->ci == c->prev->cibase) { + if (!c->vmexec && c->prev->ci == c->prev->cibase) { mrb_value exc = mrb_exc_new_lit(mrb, E_FIBER_ERROR, "double resume"); mrb_exc_set(mrb, exc); goto L_RAISE; @@ -2089,8 +2089,14 @@ RETRY_TRY_BLOCK: /* automatic yield at the end */ c->status = MRB_FIBER_TERMINATED; mrb->c = c->prev; - c->prev = NULL; mrb->c->status = MRB_FIBER_RUNNING; + c->prev = NULL; + if (c->vmexec) { + mrb_gc_arena_restore(mrb, ai); + c->vmexec = FALSE; + mrb->jmp = prev_jmp; + return v; + } ci = mrb->c->ci; } CHECKPOINT_RESTORE(RBREAK_TAG_RETURN) { |
