Prechádzať zdrojové kódy

arreglo el parseo de parametros; en tick() tenia una COPIA del proceso, no podia modificarlo

David 10 rokov pred
rodič
commit
bd8faebd11
1 zmenil súbory, kde vykonal 20 pridanie a 17 odobranie
  1. 20 17
      sched_mfq.cpp

+ 20 - 17
sched_mfq.cpp

@@ -9,11 +9,11 @@ using namespace std;
 
 SchedMFQ::SchedMFQ(vector<int> argn) {
 	// MFQ recibe los quantums por parámetro
-	n_colas = argn[1];
+	n_colas = argn.size()-1;
 	q_cola = new uint[n_colas];
 
 	for( uint i = 0; i < n_colas ;i++ ){
-		q_cola[i] = argn[2+i];
+		q_cola[i] = argn[1+i];
 		v_cola.push_back(std::map<int,process>());
 	}
 }
@@ -48,58 +48,61 @@ uint SchedMFQ::pid_queue(uint pid){
 int SchedMFQ::ready_at(uint qn){
 	if (v_cola[qn].size() == 0)
 		return -1;
+
 	for (it_type it = v_cola[qn].begin(); it != v_cola[qn].end(); it++) {
-		if (it->second.state == READY)
+		//cout << "Mirando al pid " << it->first << endl;
+		if (it->second.state == READY){
+			//cout << "Me gusta " << it->first << endl;
 			return it->first;
+		}
 	}
+
 	return -1;
 }
 uint SchedMFQ::next_pid(){
 	for( uint q = 0; q < n_colas; q++ ){
+		//cout << "Mirando en la pila " << q << endl;
 		int p = ready_at(q);
-		if (p!=-1){
+		if (p != -1)
 			return p; //Algun proceso listo
-		}
 	}
 
 	return IDLE_TASK;
-	//return 65535;
 }
 
 int SchedMFQ::tick(int core, const enum Motivo m) {
 	uint switch_process = 0;
-	uint cur_pid = current_pid(core);
+	int cur_pid = current_pid(core);
+
 	if (cur_pid == IDLE_TASK)
 		return next_pid();
 
 	uint p_q = pid_queue(cur_pid);
-	//cout << "curpid " << cur_pid << endl; //-1
-	//cout << "p_q " << p_q << endl; //65535, segfault
+	process* cur_process=&(v_cola[p_q][cur_pid]);
 
-	process cur_process=v_cola[p_q][cur_pid];
-	//cout << "asd4" << endl;
 	switch (m) {
 	case TICK:
-		cur_process.quantum_count++;
-		if (cur_process.quantum_count >= q_cola[p_q]) {
+		cur_process->quantum_count++;
+		if (cur_process->quantum_count >= q_cola[p_q]) {
 			switch_process = 1;
-			cur_process.state = READY;
-			cur_process.quantum_count = 0;
+			cur_process->state = READY;
+			cur_process->quantum_count = 0;
 			if(p_q < n_colas) { //Hay una cola "peor" para ir; lo llevo
-				v_cola[p_q+1][cur_pid]=cur_process;
+				v_cola[p_q+1][cur_pid]=*cur_process;
 				v_cola[p_q].erase(cur_pid);
 			}
 		}
 		break;
 	case BLOCK:
 		switch_process = 1;
-		cur_process.state = BLOCKED;
+		cur_process->state = BLOCKED;
 		break;
 	case EXIT:
 		switch_process = 1;
 		v_cola[p_q].erase(cur_pid);
 		break;
 	}
+
 	if (switch_process)
 		return next_pid();