فهرست منبع

Cambios en sched RR

Fabian 10 سال پیش
والد
کامیت
763e2fd6c3
1فایلهای تغییر یافته به همراه13 افزوده شده و 13 حذف شده
  1. 13 13
      sched_rr.cpp

+ 13 - 13
sched_rr.cpp

@@ -25,34 +25,34 @@ void SchedRR::unblock(int pid) {
 	p_map[pid].state=READY;
 }
 
-int SchedRR::next_pid(){
-
-	// FIXME Usar colas?
-	//Hasta el fin de la 'lista', hay alguno listo?
-	for( it_type it = p_map.find(cur_pid); it != p_map.end(); it++) {
-		if (it->first==cur_pid || it->first==IDLE_TASK) //Como arranco del sig?
+int SchedRR::next_pid() {
+	// Hasta el fin de la 'lista', hay alguno listo?
+	for(it_type it = ++p_map.find(cur_pid); it != p_map.end(); it++) {
+		if (it->first == IDLE_TASK)
 			continue;
 
-		if (it->second.state == READY){
+		if (it->second.state == READY)
 			return it->first;
-		}
 	}
 
-	//Desde el inicio hasta donde estaba, hay alguno listo?
-	for( it_type it = p_map.begin(); it != p_map.find(cur_pid); it++) {
-		if (it->first==IDLE_TASK) 
+	// Desde el inicio hasta donde estaba, hay alguno listo?
+	for(it_type it = p_map.begin(); it != p_map.find(cur_pid); it++) {
+		if (it->first == IDLE_TASK)
 			continue;
+
 		if (it->second.state == READY)
 			return it->first;
 	}
 
-	if (p_map[cur_pid].state==READY)
+	if (p_map[cur_pid].state == READY)
 		return cur_pid;
 
 	return IDLE_TASK;
 }
+
 int SchedRR::tick(int cpu, const enum Motivo m) {
 	uint switch_process=0;
+
 	switch(m) {
 		case TICK:
 			p_map[cur_pid].quantum_count++;
@@ -71,7 +71,7 @@ int SchedRR::tick(int cpu, const enum Motivo m) {
 	if (cur_pid==IDLE_TASK)
 		switch_process=1;
 
-	if (p_map[cur_pid].quantum_count>quantum) {
+	if (p_map[cur_pid].quantum_count>=quantum) {
 		switch_process=1;
 		p_map[cur_pid].state=READY;
 		p_map[cur_pid].quantum_count=0;