Skip to content

Commit b7c2a64

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 d95ce1b commit b7c2a64

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

kernel/task.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,11 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
899899
tcb->id = kcb->next_tid++;
900900
kcb->task_count++; /* Cached count of active tasks for quick access */
901901

902-
if (!kcb->task_current)
903-
kcb->task_current = node;
902+
/* Binding ready queue node */
903+
tcb->rq_node.data = tcb;
904+
905+
/* Push node to ready queue */
906+
sched_enqueue_task(tcb);
904907

905908
CRITICAL_LEAVE();
906909

@@ -920,7 +923,6 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
920923

921924
/* Add to cache and mark ready */
922925
cache_task(tcb->id, tcb);
923-
sched_enqueue_task(tcb);
924926

925927
return tcb->id;
926928
}

0 commit comments

Comments
 (0)