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

2.2: rewrote scheduler and fixed all issues, all tests now pass

parent 5896562b
No related branches found
Tags tp1-act-2-2
No related merge requests found
......@@ -574,32 +574,24 @@ scheduler(void)
// a race between an interrupt and WFI, which would
// cause a lost wakeup.
intr_off();
p = pick_highest_priority_runnable_proc();
int found = 0;
for(p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if(p->state == RUNNABLE) {
// Switch to chosen process. It is the process's job
// to release its lock and then reacquire it
// before jumping back to us.
p->state = RUNNING;
c->proc = p;
swtch(&c->scheduler, &p->context);
// Process is done running for now.
// It should have changed its p->state before coming back.
c->proc = 0;
found = 1;
}
if (p) {
p->state = RUNNING;
c->proc = p;
remove_from_prio_queue(p);
insert_into_prio_queue(p);
// ensure that release() doesn't enable interrupts.
// again to avoid a race between interrupt and WFI.
c->intena = 0;
release(&prio_lock);
swtch(&c->scheduler, &p->context);
c->proc = 0;
release(&p->lock);
}
if(found == 0){
} else {
asm volatile("wfi");
}
}
......
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