Skip to content

Commit a44c86e

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 0353b5c commit a44c86e

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
@@ -806,8 +806,14 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
806806
tcb->id = kcb->next_tid++;
807807
kcb->task_count++; /* Cached count of active tasks for quick access */
808808

809+
/* Binding ready queue node */
810+
tcb->rq_node.data = tcb;
811+
809812
if (!kcb->task_current)
810-
kcb->task_current = node;
813+
kcb->task_current = &tcb->rq_node;
814+
815+
/* Push node to ready queue */
816+
sched_enqueue_task(tcb);
811817

812818
CRITICAL_LEAVE();
813819

@@ -827,7 +833,6 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
827833

828834
/* Add to cache and mark ready */
829835
cache_task(tcb->id, tcb);
830-
sched_enqueue_task(tcb);
831836

832837
return tcb->id;
833838
}

0 commit comments

Comments
 (0)