| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include <map>
- #include <queue>
- #include "sched_rr.h"
- #include "basesched.h"
- #include <iostream>
- 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() {
- p_map.clear();
- }
- void SchedRR::load(int pid) {
- cout << "Load: " << pid << endl;
- p_map[pid]=READY;
- }
- void SchedRR::unblock(int pid) {
- p_map[pid]=READY;
- }
- 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) {
- switch(m) {
- case TICK:
- p_map[cur_pid]=READY;
- break;
- case BLOCK:
- 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;
- }
|