Skip to content
Snippets Groups Projects
Commit 5896562b authored by Fache Charles's avatar Fache Charles
Browse files

2.1: wrote pick_highest_priority_runnable_proc(), it passes all tests

parent fa14f084
No related branches found
Tags tp1-act-2-1
No related merge requests found
No preview for this file type
......@@ -509,6 +509,49 @@ wait(uint64 addr)
}
}
// Finds highest priority, runnable, process and
// returns it, returns 0 if no runnable process is found.
struct proc*
pick_highest_priority_runnable_proc() {
for (int i = 0; i < NPRIO; i++) {
struct list_proc* list = prio[i];
acquire(&prio_lock);
struct list_proc* observed = list;
while(observed) {
struct proc* p = observed->p;
acquire(&p->lock);
if (p->state == RUNNABLE) {
return p;
}
release(&p->lock);
observed = observed->next;
}
release(&prio_lock);
}
return 0;
// for (struct list_proc* lp = prio[0]; lp < prio[NPRIO]; lp++) { // go through all priority lists
// acquire(&prio_lock);
// struct list_proc* observed = lp;
// while(observed) {
// struct proc* p = observed->p;
// acquire(&p->lock);
// if (p->state == RUNNABLE) {
// return 0;
// }
// release(&p->lock);
// observed = observed->next;
// }
// release(&prio_lock);
// }
// return 0; // if no runnable process is found, return 0, holding no lock
}
// Per-CPU process scheduler.
// Each CPU calls scheduler() after setting itself up.
// Scheduler never returns. It loops, doing:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment