sched_fcfs.cpp 760 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "sched_fcfs.h"
  2. using namespace std;
  3. SchedFCFS::SchedFCFS(vector<int> argn) {
  4. // FCFS recibe la cantidad de cores.
  5. }
  6. SchedFCFS::~SchedFCFS() {
  7. }
  8. void SchedFCFS::load(int pid) {
  9. q.push(pid); // llegó una tarea nueva
  10. }
  11. void SchedFCFS::unblock(int pid) {
  12. // Uy! unblock!... bueno, ya seguir'a en el próximo tick
  13. }
  14. int SchedFCFS::tick(int cpu, const enum Motivo m) {
  15. if (m == EXIT) {
  16. // Si el pid actual terminó, sigue el próximo.
  17. if (q.empty()) return IDLE_TASK;
  18. else {
  19. int sig = q.front(); q.pop();
  20. return sig;
  21. }
  22. } else {
  23. // Siempre sigue el pid actual mientras no termine.
  24. if (current_pid(cpu) == IDLE_TASK && !q.empty()) {
  25. int sig = q.front(); q.pop();
  26. return sig;
  27. } else {
  28. return current_pid(cpu);
  29. }
  30. }
  31. }