sched_sjf.h 898 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef __SCHED_SJF__
  2. #define __SCHED_SJF__
  3. #include <map>
  4. #include <vector>
  5. #include <queue>
  6. #include <algorithm>
  7. #include "basesched.h"
  8. using namespace std;
  9. class SchedSJF : public SchedBase {
  10. public:
  11. SchedSJF(std::vector<int> argn);
  12. ~SchedSJF();
  13. virtual void initialize() {};
  14. virtual void load(int pid);
  15. virtual void unblock(int pid);
  16. virtual int tick(int cpu, const enum Motivo m);
  17. private:
  18. uint nucleos;
  19. struct Process {
  20. int pid;
  21. uint duration;
  22. // Esto permite ordenar por la duración mínima
  23. int operator()(const Process& me, const Process& other) {
  24. return me.duration > other.duration;
  25. }
  26. };
  27. bool firstTick;
  28. std::map<int, Process> p_map; // Mapeo de los procesos
  29. typedef std::map<int,Process>::iterator it_type;
  30. std::priority_queue<Process, std::vector<Process>, Process> pq; // Procesos en estado READY o RUNNING
  31. };
  32. #endif