Skip to content

Commit 72d3d91

Browse files
committed
Refactor mo_task_spawn() for O(1) scheduler support
Previously, mo_task_spawn() only created a task and appended it to the global task list (kcb->tasks), assigning the first task directly from the global list node. This change adds a call to sched_enqueue_task() within the critical section to enqueue the task into the ready queue and safely initialize its scheduling attributes. The first task assignment is now aligned with the RR cursor mechanism to ensure consistency with the O(1) scheduler.
1 parent 2844df3 commit 72d3d91

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

kernel/task.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,15 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
765765
tcb->id = kcb->next_tid++;
766766
kcb->task_count++; /* Cached count of active tasks for quick access */
767767

768-
if (!kcb->task_current)
769-
kcb->task_current = node;
768+
/* Binding ready queue node */
769+
tcb->rq_node.data = tcb;
770+
771+
/* Push node to ready queue */
772+
sched_enqueue_task(tcb);
773+
if (!kcb->task_current) {
774+
kcb->task_current = kcb->harts->rr_cursors[tcb->prio_level];
775+
tcb->state = TASK_RUNNING;
776+
}
770777

771778
CRITICAL_LEAVE();
772779

@@ -780,7 +787,6 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
780787

781788
/* Add to cache and mark ready */
782789
cache_task(tcb->id, tcb);
783-
sched_enqueue_task(tcb);
784790

785791
return tcb->id;
786792
}

0 commit comments

Comments
 (0)