Skip to content

Commit 3b83317

Browse files
committed
Refactor mo_task_spawn() for the new scheduler
This commit refactors mo_task_spawn() to better align with the new O(1) scheduler design. The task control block (tcb_t) now embeds its list node directly, removing the need for an external allocation and simplifying the ready-queue bookkeeping. The enqueue operation is also moved inside a critical section to guarantee consistent state updates during task creation. In addition, the previous “first task assignment” logic is removed. The first created task is always the system idle task during startup, so this special-case handling is no longer required. These changes improve system consistency and allow task priority migration to occur even before a newly created task runs for the first time.
1 parent 1958450 commit 3b83317

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
@@ -747,8 +747,11 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
747747
tcb->id = kcb->next_tid++;
748748
kcb->task_count++; /* Cached count of active tasks for quick access */
749749

750-
if (!kcb->task_current)
751-
kcb->task_current = node;
750+
/* Binding ready queue node */
751+
tcb->rq_node.data = tcb;
752+
753+
/* Push node to ready queue */
754+
sched_enqueue_task(tcb);
752755

753756
CRITICAL_LEAVE();
754757

@@ -762,7 +765,6 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
762765

763766
/* Add to cache and mark ready */
764767
cache_task(tcb->id, tcb);
765-
sched_enqueue_task(tcb);
766768

767769
return tcb->id;
768770
}

0 commit comments

Comments
 (0)