mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-task: add gc protection and optimize task operations
Implements dual-mechanism GC protection and optimizes task lookup using pointer arithmetic based on PicoRuby reference implementation. GC Protection: - Add mrb_gc_register/unregister to protect Task objects - Implement mrb_task_mark_all() to mark task contexts during GC - Store proc reference in mrb_task to prevent premature collection - Integrate marking into gc.c root_scan_phase Performance Optimizations: - Add MRB2TASK macro for O(1) context-to-task conversion - Optimize Task.current: O(n) queue search -> O(1) pointer arithmetic - Optimize Task.pass: simplify to root context check - Optimize Task.join: use MRB2TASK for current task lookup Bug Fixes: - Fix MRB_TASK_CREATED/STOPPED to use MRB_FIBER_TERMINATED - Add safety check to prevent execution of terminated tasks - Initialize callinfo PC to bytecode start in task_init_context Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -266,4 +266,9 @@ mrb_value mrb_bint_lcm(mrb_state *mrb, mrb_value x, mrb_value y);
|
||||
mrb_value mrb_bint_abs(mrb_state *mrb, mrb_value x);
|
||||
#endif
|
||||
|
||||
#ifdef MRB_USE_TASK_SCHEDULER
|
||||
/* GC marking for task scheduler */
|
||||
void mrb_task_mark_all(mrb_state *mrb);
|
||||
#endif
|
||||
|
||||
#endif /* MRUBY_INTERNAL_H */
|
||||
|
||||
Reference in New Issue
Block a user