sched: add kernel thread creation and SMP-aware thread scheduling

This commit is contained in:
2023-05-04 21:43:18 +01:00
parent bb524c1576
commit 7d321fb7f0
5 changed files with 86 additions and 2 deletions

View File

@@ -71,10 +71,31 @@ int thread_priority(struct thread *thr)
return thr->tr_prio;
}
struct thread *create_kernel_thread(void(*fn)(void))
{
struct task *kernel = kernel_task();
struct thread *thr = thread_alloc();
thr->tr_parent = kernel;
thr->tr_prio = PRIO_NORMAL;
thr->tr_state = THREAD_READY;
thr->tr_quantum_target = default_quantum();
thread_init(thr, (uintptr_t)fn);
unsigned long flags;
task_lock_irqsave(kernel, &flags);
queue_push_back(&kernel->t_threads, &thr->tr_threads);
task_unlock_irqrestore(kernel, flags);
schedule_thread_on_cpu(thr);
return thr;
}
struct thread *create_idle_thread(void)
{
struct task *idle = idle_task();
struct thread *thr = thread_alloc();
thr->tr_parent = idle;