mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #6717 from hasumikin/fix/Task-critical-section
Fix mruby-task: wrapping by critical section and setting initial task receiver to top_self
This commit is contained in:
@@ -278,8 +278,8 @@ task_init_context(mrb_state *mrb, mrb_task *t, const struct RProc *proc)
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy receiver from current context */
|
||||
c->stbase[0] = mrb->c->ci->stack[0];
|
||||
/* Set receiver to top self */
|
||||
c->stbase[0] = mrb_top_self(mrb);
|
||||
|
||||
/* Initialize callinfo stack */
|
||||
static const mrb_callinfo ci_zero = { 0 };
|
||||
@@ -459,13 +459,16 @@ mrb_task_run(mrb_state *mrb)
|
||||
|
||||
/* No task ready - check if all tasks are done */
|
||||
if (!t) {
|
||||
/* If there are tasks waiting or suspended, idle */
|
||||
if (q_waiting_ || q_suspended_) {
|
||||
mrb_hal_task_idle_cpu(mrb);
|
||||
continue;
|
||||
mrb_task_disable_irq();
|
||||
mrb_bool exiting = !q_ready_ && !q_waiting_ && !q_suspended_;
|
||||
mrb_task_enable_irq();
|
||||
if (exiting) {
|
||||
/* All tasks are dormant - scheduler done */
|
||||
break;
|
||||
}
|
||||
/* All tasks are dormant - scheduler done */
|
||||
break;
|
||||
/* If there are tasks waiting or suspended, idle */
|
||||
mrb_hal_task_idle_cpu(mrb);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Safety check - don't execute terminated tasks */
|
||||
|
||||
Reference in New Issue
Block a user