Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/proc.c b/proc.c
- index bcdbfea..a32a672 100644
- --- a/proc.c
- +++ b/proc.c
- @@ -257,18 +257,29 @@ wait(void)
- void
- scheduler(void)
- {
- + int no_runnable;
- struct proc *p;
- - for(;;){
- + for(no_runnable = 0;;){
- // Enable interrupts on this processor.
- sti();
- + // If no runnable processes were found last pass then halt
- + // the processor
- + if(no_runnable) hlt();
- +
- + // Set no_runnable
- + no_runnable = 1;
- +
- // Loop over process table looking for process to run.
- acquire(&ptable.lock);
- for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
- if(p->state != RUNNABLE)
- continue;
- + // We found at least one runnable proc
- + no_runnable = 0;
- +
- // Switch to chosen process. It is the process's job
- // to release ptable.lock and then reacquire it
- // before jumping back to us.
- diff --git a/x86.h b/x86.h
- index 3949900..7d14145 100644
- --- a/x86.h
- +++ b/x86.h
- @@ -117,6 +117,12 @@ sti(void)
- asm volatile("sti");
- }
- +static inline void
- +hlt(void)
- +{
- + asm volatile("hlt");
- +}
- +
- static inline uint
- xchg(volatile uint *addr, uint newval)
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement