Untitled
unknown
plain_text
a year ago
891 B
6
Indexable
void
scheduler(void)
{
struct proc *p;
struct proc *high_priority_proc;
for(;;){
// Enable interrupts on this processor.
sti();
acquire(&ptable.lock);
high_priority_proc = 0;
// Find the process with the highest priority
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
if(p->state != RUNNABLE)
continue;
if(!high_priority_proc || p->priority < high_priority_proc->priority){
high_priority_proc = p;
}
}
if(high_priority_proc){
p = high_priority_proc;
// Switch to the chosen process
proc = p;
switchuvm(p);
p->state = RUNNING;
swtch(&cpu->scheduler, proc->context);
switchkvm();
proc = 0;
}
release(&ptable.lock);
}
}
Editor is loading...
Leave a Comment