Skip to content

Commit 4a6e6c1

Browse files
committed
Refactor mo_task_spawn() for the new scheduler
This commit refactors mo_task_spawn() to align with the new O(1) scheduler design. The task control block (tcb_t) embeds its list node during task creation. The enqueue operation is moved inside a critical section to guarantee consistent enqueuing process during task creation. The “first task assignment” logic is removed because first task has been assigned to system idle task as previous commit mentioned.
1 parent 9bc9235 commit 4a6e6c1

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)