sched_rr.cpp 770 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <map>
  2. #include <queue>
  3. #include "sched_rr.h"
  4. #include "basesched.h"
  5. #include <iostream>
  6. using namespace std;
  7. SchedRR::SchedRR(vector<int> argn) {
  8. // Round robin recibe la cantidad de cores y sus cpu_quantum por parámetro
  9. nucleos = argn[0];
  10. quantum = argn[1];
  11. cur_pid = IDLE_TASK;
  12. }
  13. SchedRR::~SchedRR() {
  14. p_map.clear();
  15. }
  16. void SchedRR::load(int pid) {
  17. p_map[pid]=WAITING;
  18. }
  19. void SchedRR::unblock(int pid) {
  20. p_map[pid]=READY;
  21. }
  22. int SchedRR::next_pid(){
  23. return IDLE_TASK;
  24. }
  25. int SchedRR::tick(int cpu, const enum Motivo m) {
  26. switch(m) {
  27. case TICK:
  28. p_map[cur_pid]=READY;
  29. break;
  30. case BLOCK:
  31. p_map[cur_pid]=BLOCKED;
  32. break;
  33. case EXIT:
  34. p_map.erase(cur_pid);
  35. break;
  36. }
  37. cur_pid=next_pid();
  38. p_map[cur_pid]=RUNNING;
  39. return 0;
  40. }