Skip to content

Commit 5a77b20

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 6761f89 commit 5a77b20

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

kernel/task.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,14 @@ 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+
823826
if (!kcb->task_current)
824-
kcb->task_current = node;
827+
kcb->task_current = &tcb->rq_node;
828+
829+
/* Push node to ready queue */
830+
sched_enqueue_task(tcb);
825831

826832
CRITICAL_LEAVE();
827833

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

842848
/* Add to cache and mark ready */
843849
cache_task(tcb->id, tcb);
844-
sched_enqueue_task(tcb);
845850

846851
return tcb->id;
847852
}

0 commit comments

Comments
 (0)