diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/task/sched.cpp | 10 | ||||
-rw-r--r-- | src/kernel/task/sched.h | 7 | ||||
-rw-r--r-- | src/kernel/task/task.cpp | 6 |
3 files changed, 13 insertions, 10 deletions
diff --git a/src/kernel/task/sched.cpp b/src/kernel/task/sched.cpp index c17f271..5b3f007 100644 --- a/src/kernel/task/sched.cpp +++ b/src/kernel/task/sched.cpp @@ -3,10 +3,6 @@ #include <mem/mem.h> #include <ui/vt.h> -// Lower priority numbers have high priority. Priorities must start at 0. -#define PRIORITIES 3 // we have 3 priority levels -#define PRIORITY(t) (t->process->privilege) //get priority for a thread - extern thread *idle_thread; static thread *queue[PRIORITIES] = {0}, *last[PRIORITIES] = {0}; @@ -34,9 +30,11 @@ static thread *sched_dequeueFrom(int qid) { } /* Used by task.c. Enqueus a thread in the corresponding priority queue. */ -void sched_enqueue(thread *t) { +void sched_enqueue(thread *t, int priority) { if (t == idle_thread) return; - sched_enqueueIn(t, PRIORITY(t)); + if (priority >= PRIORITIES) priority = PRIORITIES - 1; + if (priority < 0) return; + sched_enqueueIn(t, priority); } /* Used by task.c. Pops a thread from the lowest priority non-empty queue. */ diff --git a/src/kernel/task/sched.h b/src/kernel/task/sched.h index 1432b02..590a810 100644 --- a/src/kernel/task/sched.h +++ b/src/kernel/task/sched.h @@ -3,7 +3,12 @@ #include "task.h" -void sched_enqueue(thread *t); +#define PRIORITIES 3 // we have 3 priority levels +#define TP_LOW 2 +#define TP_MED 1 +#define TP_HIGH 0 + +void sched_enqueue(thread *t, int priority); void sched_remove(thread *t); thread *sched_dequeue(); diff --git a/src/kernel/task/task.cpp b/src/kernel/task/task.cpp index ad9ce50..46fb4d4 100644 --- a/src/kernel/task/task.cpp +++ b/src/kernel/task/task.cpp @@ -81,7 +81,7 @@ void schedule() { current_thread->esp = esp; current_thread->ebp = ebp; current_thread->eip = eip; - if (current_thread->state == TS_RUNNING) sched_enqueue(current_thread); + if (current_thread->state == TS_RUNNING) sched_enqueue(current_thread, TP_LOW); } current_thread = sched_dequeue(); @@ -137,7 +137,7 @@ void thread_goInactive() { void thread::wakeUp() { if (state == TS_WAKEWAIT) { state = TS_RUNNING; - sched_enqueue(this); + sched_enqueue(this, TP_HIGH); } } @@ -269,7 +269,7 @@ thread::thread(class process *proc, thread_entry entry_point, void *data, void * proc->threads = this; state = TS_RUNNING; - sched_enqueue(this); + sched_enqueue(this, TP_MED); } /* Creates a new process. Creates a struct process and fills it up. */ |