#include #include #include #include "sched_sjf.h" using namespace std; SchedSJF::SchedSJF(vector argn) { /* Constructor SchedSJF: Recibe la cantidad de cores */ nucleos = argn[1]; for (uint i = 2; i < argn.size(); i++) { // Cargamos los procesos con un id y una duration uint duration = argn[i]; p_map[i - 2].duration = duration; } } SchedSJF::~SchedSJF() { p_map.clear(); // Limpiamos el mapeo de procesos while (!pq.empty()) pq.pop(); // Clean the priority queue } void SchedSJF::load(int pid) { uint duration = p_map[pid].duration; // Get Process duration pq.push(Process{pid, duration}); // Push the Process to the priority queue } void SchedSJF::unblock(int pid) { /* SchedSJF solo corre tasks del tipo TaskCPU, entonces no hay acciones especificadas para este método. */ cout << "Unblock process con " << pid; } int SchedSJF::tick(int cpu, const enum Motivo m) { uint cur_pid = current_pid(cpu); if (cur_pid == IDLE_TASK || m == EXIT) { // Caso donde m == EXIT o cpu IDLE if (!pq.empty()) { // Hay más tareas para ejecutar int next_pid = pq.top().pid; pq.pop(); return next_pid; } else { // No hay más tareas encoladas, devolver IDLE return IDLE_TASK; } } else if (m == TICK) { return cur_pid; // El proceso esta corriendo } else if (m ==BLOCK) { // Proceso con estado BLOCK, no sucede en este scheduler // pero si pasa lo esperamos hasta que termine return cur_pid; } }