diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-02 08:41:13 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-02 08:41:44 +0900 |
| commit | aea5880c10af262957e597cf875f38461c2c54e3 (patch) | |
| tree | 7ea0a85f11705e18babd37d8141e48c9e40f319b | |
| parent | 5cd52d2d691f9a193c97378e7456e4e286c812fb (diff) | |
| download | mruby-aea5880c10af262957e597cf875f38461c2c54e3.tar.gz mruby-aea5880c10af262957e597cf875f38461c2c54e3.zip | |
Small refactoring in `fiber.c`.
| -rw-r--r-- | mrbgems/mruby-fiber/src/fiber.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/mrbgems/mruby-fiber/src/fiber.c b/mrbgems/mruby-fiber/src/fiber.c index 17ce77c5d..b702a3811 100644 --- a/mrbgems/mruby-fiber/src/fiber.c +++ b/mrbgems/mruby-fiber/src/fiber.c @@ -191,14 +191,21 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr fiber_check_cfunc(mrb, c); status = c->status; - if (resume && status == MRB_FIBER_TRANSFERRED) { - mrb_raise(mrb, E_FIBER_ERROR, "resuming transferred fiber"); - } - if (status == MRB_FIBER_RUNNING || status == MRB_FIBER_RESUMED) { + switch (status) { + case MRB_FIBER_TRANSFERRED: + if (resume) { + mrb_raise(mrb, E_FIBER_ERROR, "resuming transferred fiber"); + } + break; + case MRB_FIBER_RUNNING: + case MRB_FIBER_RESUMED: mrb_raise(mrb, E_FIBER_ERROR, "double resume"); - } - if (status == MRB_FIBER_TERMINATED) { + break; + case MRB_FIBER_TERMINATED: mrb_raise(mrb, E_FIBER_ERROR, "resuming dead fiber"); + break; + default: + break; } old_c->status = resume ? MRB_FIBER_RESUMED : MRB_FIBER_TRANSFERRED; c->prev = resume ? mrb->c : (c->prev ? c->prev : mrb->root_c); |
