mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-task: add core data structures to mrb_state
extend mrb_fiber_state enum with task-specific states: - MRB_TASK_CREATED: task context initialized - MRB_TASK_STOPPED: task execution finished add mrb_task_state structure to mrb_state: - task queues array (dormant, ready, waiting, suspended) - tick counter for scheduling - wakeup_tick for sleep timing - switching flag for context switches remove duplicate mrb_task_state definition from task.h since it is now defined in include/mruby.h. all changes guarded by MRB_USE_TASK_SCHEDULER for zero overhead when disabled. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -187,6 +187,10 @@ enum mrb_fiber_state {
|
||||
MRB_FIBER_SUSPENDED,
|
||||
MRB_FIBER_TRANSFERRED,
|
||||
MRB_FIBER_TERMINATED,
|
||||
#ifdef MRB_USE_TASK_SCHEDULER
|
||||
MRB_TASK_CREATED,
|
||||
MRB_TASK_STOPPED,
|
||||
#endif
|
||||
};
|
||||
|
||||
struct mrb_context {
|
||||
@@ -243,6 +247,17 @@ struct mrb_jmpbuf;
|
||||
|
||||
typedef void (*mrb_atexit_func)(struct mrb_state*);
|
||||
|
||||
#ifdef MRB_USE_TASK_SCHEDULER
|
||||
struct mrb_tcb;
|
||||
|
||||
typedef struct mrb_task_state {
|
||||
struct mrb_tcb *queues[4]; /* Task queues (dormant, ready, waiting, suspended) */
|
||||
volatile uint32_t tick; /* Current tick count */
|
||||
volatile uint32_t wakeup_tick; /* Next wakeup tick */
|
||||
volatile mrb_bool switching; /* Context switch pending flag */
|
||||
} mrb_task_state;
|
||||
#endif
|
||||
|
||||
typedef struct mrb_state {
|
||||
struct mrb_jmpbuf *jmp;
|
||||
|
||||
@@ -313,6 +328,10 @@ typedef struct mrb_state {
|
||||
mrb_atexit_func *atexit_stack;
|
||||
#endif
|
||||
uint16_t atexit_stack_len;
|
||||
|
||||
#ifdef MRB_USE_TASK_SCHEDULER
|
||||
mrb_task_state task; /* Task scheduler state */
|
||||
#endif
|
||||
} mrb_state;
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,17 +56,11 @@ typedef struct mrb_tcb {
|
||||
} mrb_tcb;
|
||||
|
||||
/*
|
||||
* Task scheduler state (part of mrb_state)
|
||||
* Task queue configuration
|
||||
* (mrb_task_state is defined in mruby.h)
|
||||
*/
|
||||
#define MRB_NUM_TASK_QUEUE 4
|
||||
|
||||
typedef struct mrb_task_state {
|
||||
mrb_tcb *queues[MRB_NUM_TASK_QUEUE]; /* Task queues */
|
||||
volatile uint32_t tick; /* Current tick count */
|
||||
volatile uint32_t wakeup_tick; /* Next wakeup tick */
|
||||
volatile mrb_bool switching; /* Context switch pending flag */
|
||||
} mrb_task_state;
|
||||
|
||||
/* Queue indices */
|
||||
#define MRB_TASK_QUEUE_DORMANT 0
|
||||
#define MRB_TASK_QUEUE_READY 1
|
||||
|
||||
Reference in New Issue
Block a user