Quellcode durchsuchen

ej4 .. se muere el cur_pid al hacer exit()

David vor 10 Jahren
Ursprung
Commit
eb947433ba
3 geänderte Dateien mit 42 neuen und 3 gelöschten Zeilen
  1. 5 0
      Makefile
  2. 35 2
      sched_rr.cpp
  3. 2 1
      sched_rr.h

+ 5 - 0
Makefile

@@ -39,3 +39,8 @@ ejercicio2: all
 
 ejercicio3: all
 	./simusched ejer3.tsk 1 2 99 SchedFCFS | ./graphsched.py > informe/imagenes/ejercicio3_1core.png
+
+ejercicio4: all
+	./simusched ejer2.tsk 1 2 99 SchedRR 1 02 | ./graphsched.py > informe/imagenes/ejercicio2_1core_02q.png
+	./simusched ejer2.tsk 1 2 99 SchedRR 1 05 | ./graphsched.py > informe/imagenes/ejercicio2_1core_05q.png
+	./simusched ejer2.tsk 1 2 99 SchedRR 1 10 | ./graphsched.py > informe/imagenes/ejercicio2_1core_10q.png

+ 35 - 2
sched_rr.cpp

@@ -17,9 +17,9 @@ SchedRR::~SchedRR() {
 	p_map.clear();
 }
 
-
 void SchedRR::load(int pid) {
-	p_map[pid]=WAITING;
+	cout << "Load: " << pid << endl;
+	p_map[pid]=READY;
 }
 
 void SchedRR::unblock(int pid) {
@@ -27,6 +27,31 @@ void SchedRR::unblock(int pid) {
 }
 
 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==cur_pid || it->first==IDLE_TASK) //Como arranco del sig?
+			continue;
+
+		cout << it->first << " => " << it->second << endl;
+
+		if (it->second == 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) 
+			continue;
+		cout << it->first << " ==> " << it->second << endl;
+		if (it->second == READY)
+			return it->first;
+	}
+
+	if (p_map[cur_pid]==READY)
+		return cur_pid;
+
 	return IDLE_TASK;
 }
 int SchedRR::tick(int cpu, const enum Motivo m) {
@@ -38,10 +63,18 @@ int SchedRR::tick(int cpu, const enum Motivo m) {
 			p_map[cur_pid]=BLOCKED;
 			break;
 		case EXIT:
+			cout << "exit" << endl;
 			p_map.erase(cur_pid);
+
+			for( it_type it = p_map.begin(); it != p_map.end(); it++) {
+			    cout << "m[" << it->first << "] = " << it->second << endl;
+			}
+
+			cur_pid=IDLE_TASK;
 			break;
 	}
 	cur_pid=next_pid();
+	cout << cur_pid << endl;
 	p_map[cur_pid]=RUNNING;
 	
 	return 0;

+ 2 - 1
sched_rr.h

@@ -22,7 +22,7 @@ class SchedRR : public SchedBase {
 		uint quantum;
 		int cur_pid;
 		
-		enum state { WAITING, READY, BLOCKED, RUNNING };
+		enum state { READY, BLOCKED, RUNNING };
 		
 		struct process{
 			int pid;
@@ -30,6 +30,7 @@ class SchedRR : public SchedBase {
 		} ;
 		
 		std::map<int, enum state> p_map;
+		typedef std::map<int,enum state>::iterator it_type;
 
 /* llenar */
 };