kern

diff src/sched.c @ 56:0be4615594df

finally, runqueues, blocking, waking up, idle loop etc, all seem to work fine on a single user process... Next up: try forking another one :)
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 15 Aug 2011 06:17:58 +0300
parents 88a6c4e192f9
children 437360696883
line diff
     1.1 --- a/src/sched.c	Mon Aug 15 04:03:39 2011 +0300
     1.2 +++ b/src/sched.c	Mon Aug 15 06:17:58 2011 +0300
     1.3 @@ -30,8 +30,15 @@
     1.4  	disable_intr();
     1.5  
     1.6  	if(EMPTY(&runq)) {
     1.7 +		if(!get_current_proc()) {
     1.8 +			/* we're already in the idle process, don't reenter it
     1.9 +			 * or you'll fill up the stack very quickly.
    1.10 +			 */
    1.11 +			return;
    1.12 +		}
    1.13 +
    1.14  		idle_proc();
    1.15 -		/* this won't return, it'll just wake up in an interrupt later */
    1.16 +		return;
    1.17  	}
    1.18  
    1.19  	/* if the current process exhausted its timeslice,
    1.20 @@ -88,6 +95,9 @@
    1.21  
    1.22  	p->state = STATE_BLOCKED;
    1.23  	p->wait_addr = wait_addr;
    1.24 +
    1.25 +	/* call the scheduler to give time to another process */
    1.26 +	schedule();
    1.27  }
    1.28  
    1.29  /* wake up all the processes sleeping on this address */
    1.30 @@ -124,9 +134,14 @@
    1.31  	struct intr_frame *ifrm = get_intr_frame();
    1.32  	end_of_irq(INTR_TO_IRQ(ifrm->inum));
    1.33  
    1.34 +	set_current_pid(0);
    1.35 +
    1.36  	/* make sure interrupts are enabled before halting */
    1.37 -	enable_intr();
    1.38 -	halt_cpu();
    1.39 +	while(EMPTY(&runq)) {
    1.40 +		enable_intr();
    1.41 +		halt_cpu();
    1.42 +		disable_intr();
    1.43 +	}
    1.44  }
    1.45  
    1.46