Skip to content

Commit 85fa026

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 79fe681 commit 85fa026

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kernel/task.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,12 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
666666
tcb->id = kcb->next_tid++;
667667
kcb->task_count++; /* Cached count of active tasks for quick access */
668668

669-
if (!kcb->task_current)
670-
kcb->task_current = node;
669+
/* Push node to ready queue */
670+
sched_enqueue_task(tcb);
671+
if (!kcb->task_current) {
672+
kcb->task_current = kcb->harts->rr_cursors[tcb->prio_level];
673+
tcb->state = TASK_RUNNING;
674+
}
671675

672676
CRITICAL_LEAVE();
673677

@@ -681,7 +685,6 @@ int32_t mo_task_spawn(void *task_entry, uint16_t stack_size_req)
681685

682686
/* Add to cache and mark ready */
683687
cache_task(tcb->id, tcb);
684-
sched_enqueue_task(tcb);
685688

686689
return tcb->id;
687690
}

0 commit comments

Comments
 (0)