diff --git a/include/socks/sched.h b/include/socks/sched.h index 393f3bf..60d3933 100644 --- a/include/socks/sched.h +++ b/include/socks/sched.h @@ -156,6 +156,9 @@ static inline void task_unlock_irqrestore(struct task *task, unsigned long flags extern struct thread *thread_alloc(void); extern kern_status_t thread_init(struct thread *thr, uintptr_t ip); extern int thread_priority(struct thread *thr); +extern void idle(void); + +extern struct thread *create_idle_thread(void); extern void add_timer(struct timer *timer); extern void remove_timer(struct timer *timer); diff --git a/sched/task.c b/sched/task.c index d979334..413c41c 100644 --- a/sched/task.c +++ b/sched/task.c @@ -30,7 +30,7 @@ struct task *idle_task(void) return __idle_task; } -static void __idle_function(void) +void idle(void) { while (1) { ml_cpu_pause(); @@ -123,7 +123,7 @@ kern_status_t setup_idle_task(void) idle_thread->tr_id = 0; idle_thread->tr_parent = __idle_task; - thread_init(idle_thread, (uintptr_t)__idle_function); + thread_init(idle_thread, (uintptr_t)idle); queue_push_back(&__idle_task->t_threads, &idle_thread->tr_threads); diff --git a/sched/thread.c b/sched/thread.c index 01b7ef4..a293198 100644 --- a/sched/thread.c +++ b/sched/thread.c @@ -70,3 +70,21 @@ int thread_priority(struct thread *thr) { return thr->tr_prio; } + +struct thread *create_idle_thread(void) +{ + struct task *idle = idle_task(); + + struct thread *thr = thread_alloc(); + + thr->tr_prio = PRIO_NORMAL; + thr->tr_state = THREAD_READY; + thr->tr_quantum_target = default_quantum(); + + unsigned long flags; + task_lock_irqsave(idle, &flags); + queue_push_back(&idle->t_threads, &thr->tr_threads); + task_unlock_irqrestore(idle, flags); + + return thr; +}