| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include <map>
- #include <vector>
- #include <queue>
- #include "sched_mfq.h"
- #include "basesched.h"
- using namespace std;
- SchedMFQ::SchedMFQ(vector<int> argn) {
- // MFQ recibe los quantums por parámetro
- n_colas = argn[1];
- q_cola = new uint[n_colas];
- for( uint i = 0; i < n_colas ;i++ ){
- q_cola[i] = argn[2+i];
- v_cola.push_back(std::map<int,process>());
- }
- }
- SchedMFQ::~SchedMFQ() {
- delete[] q_cola;
- }
- void SchedMFQ::load(int pid) {
- v_cola[0][pid].state=READY; //Cargo PID en la cola de mayor prioridad
- }
- void SchedMFQ::unblock(int pid) {
- uint p_q=pid_queue(pid);
- v_cola[p_q][pid].state = READY;
- v_cola[p_q][pid].quantum_count = 0;
- if(p_q > 0) { //Hay una cola "mejor" para ir; lo llevo
- v_cola[p_q-1][pid]=v_cola[p_q][pid];
- v_cola[p_q].erase(pid);
- }
- }
- uint SchedMFQ::pid_queue(uint pid){
- for( uint i = 0; i < n_colas; i++ )
- if ( v_cola[i].count(pid) == 1) //Solo hay 0/1 key en un map
- return i;
- return 65535; // ??
- }
- int SchedMFQ::tick(int core, const enum Motivo m) {
- uint switch_process = 0;
- uint cur_pid = current_pid(core);
- uint p_q = pid_queue(cur_pid);
- switch (m) {
- case TICK:
- v_cola[p_q][cur_pid].quantum_count++;
- if (v_cola[p_q][cur_pid].quantum_count >= q_cola[p_q]) {
- switch_process = 1;
- v_cola[p_q][cur_pid].state = READY;
- v_cola[p_q][cur_pid].quantum_count = 0;
- if(p_q < n_colas) { //Hay una cola "peor" para ir; lo llevo
- v_cola[p_q+1][cur_pid]=v_cola[p_q][cur_pid];
- v_cola[p_q].erase(cur_pid);
- }
- }
- break;
- case BLOCK:
- switch_process = 1;
- v_cola[p_q][cur_pid].state = BLOCKED;
- break;
- case EXIT:
- switch_process = 1;
- v_cola[p_q].erase(cur_pid);
- break;
- }
- return 0;
- }
|