Skip to content

Commit 1d91b39

Browse files
committed
Refactor mo_task_spawn() for the new scheduler
Move sched_enqueue_task() into a critical section to protect ready_queue[] integrity, as the API modifies shared scheduler resources. Initialize the embedded rq_node when a task spawns and set its next pointer to NULL to ensure deterministic linkage for ready-queue insertion. Bind the initial task slot using rq_node instead of the global task list, matching the new ready-queue selection model. This aligns task-spawn behavior with rq_node-based scheduling semantics.
1 parent 953e3c7 commit 1d91b39

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

kernel/task.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,15 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
820820
tcb->id = kcb->next_tid++;
821821
kcb->task_count++; /* Cached count of active tasks for quick access */
822822

823+
/* Binding ready queue node */
824+
tcb->rq_node.data = tcb;
825+
tcb->rq_node.next = NULL;
826+
823827
if (!kcb->task_current)
824-
kcb->task_current = node;
828+
kcb->task_current = &tcb->rq_node;
829+
830+
/* Push node to ready queue */
831+
sched_enqueue_task(tcb);
825832

826833
CRITICAL_LEAVE();
827834

@@ -841,7 +848,6 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
841848

842849
/* Add to cache and mark ready */
843850
cache_task(tcb->id, tcb);
844-
sched_enqueue_task(tcb);
845851

846852
return tcb->id;
847853
}

0 commit comments

Comments
 (0)