David 10 anni fa
parent
commit
0c4633027f
2 ha cambiato i file con 38 aggiunte e 5 eliminazioni
  1. 24 5
      sched_rr.cpp
  2. 14 0
      sched_rr.h

+ 24 - 5
sched_rr.cpp

@@ -1,4 +1,4 @@
-#include <vector>
+#include <map>
 #include <queue>
 #include "sched_rr.h"
 #include "basesched.h"
@@ -8,22 +8,41 @@ using namespace std;
 
 SchedRR::SchedRR(vector<int> argn) {
 	// Round robin recibe la cantidad de cores y sus cpu_quantum por parámetro
+	nucleos = argn[0];
+	quantum = argn[1];
+	cur_pid = IDLE_TASK;
 }
 
 SchedRR::~SchedRR() {
-/* completar */
+	p_map.clear();
 }
 
 
 void SchedRR::load(int pid) {
-/* completar */
+	p_map[pid]=WAITING;
 }
 
 void SchedRR::unblock(int pid) {
-/* completar */
+	p_map[pid]=READY;
 }
 
+int SchedRR::next_pid(){
+	return IDLE_TASK;
+}
 int SchedRR::tick(int cpu, const enum Motivo m) {
-/* completar */
+	switch(m) {
+		case TICK:
+			p_map[cur_pid]=READY;
+			break;
+		case BLOCK:
+			p_map[cur_pid]=BLOCKED;
+			break;
+		case EXIT:
+			p_map.erase(cur_pid);
+			break;
+	}
+	cur_pid=next_pid();
+	p_map[cur_pid]=RUNNING;
+	
 	return 0;
 }

+ 14 - 0
sched_rr.h

@@ -16,7 +16,21 @@ class SchedRR : public SchedBase {
 		virtual void load(int pid);
 		virtual void unblock(int pid);
 		virtual int tick(int cpu, const enum Motivo m);	
+		virtual int next_pid();
 	private:
+		uint nucleos;
+		uint quantum;
+		int cur_pid;
+		
+		enum state { WAITING, READY, BLOCKED, RUNNING };
+		
+		struct process{
+			int pid;
+			enum state state;
+		} ;
+		
+		std::map<int, enum state> p_map;
+
 /* llenar */
 };