sched: add kernel thread creation and SMP-aware thread scheduling
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user