Advertisement
KDOXG

Process

Nov 23rd, 2019
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include "Process.hpp"
  2.  
  3. Process::Process(unsigned time, unsigned slice, unsigned memory, byte level)
  4. {
  5.     estado = EM_ESPERA;
  6.     this->time = time;
  7.     this->slice = slice;
  8.     this->memory = memory;
  9.     switch (level)
  10.     {
  11.     case 0:
  12.         this->level = 0b00000001;
  13.         break;
  14.     case 1:
  15.         this->level = 0b00000010;
  16.         break;
  17.     case 2:
  18.         this->level = 0b00000100;
  19.         break;
  20.     case 3:
  21.         this->level = 0b00001000;
  22.         break;
  23.     case 4:
  24.         this->level = 0b10010000;
  25.         break;
  26.     }
  27.     total = slice;
  28.     read = -1;
  29.     call = 0;
  30.     duration = 0;
  31. }
  32. unsigned Process::getTime()
  33. {
  34.     return time;
  35. }
  36. unsigned Process::getRead()
  37. {
  38.     return read;
  39. }
  40. unsigned Process::getTotal()
  41. {
  42.     return total;
  43. }
  44. unsigned Process::getDuration()
  45. {
  46.     return duration;
  47. }
  48. state_t Process::getStatus()
  49. {
  50.     return estado;
  51. }
  52. unsigned Process::getMemory()
  53. {
  54.     return memory;
  55. }
  56. byte Process::getLevel()
  57. {
  58.     if ((level & 0b00010000) == 0b00010000) return 4;
  59.     if ((level & 0b00001000) == 0b00001000) return 3;
  60.     if ((level & 0b00000100) == 0b00000100) return 2;
  61.     if ((level & 0b00000010) == 0b00000010) return 1;
  62.     if ((level & 0b00000001) == 0b00000001) return 0;
  63.     return 0;
  64. }
  65. void Process::setLevel()
  66. {
  67.     if ((level & 0b10000000) == 0b10000000) return; //Inicializado com prioridade 4
  68.     if (call == 10 && (level & 0b01000000) != 0b01000000)   //Incrementando a prioridade
  69.     {
  70.         level <<= 1;
  71.         if ((level & 0b00010000) == 0b00010000)
  72.             level |= 0b01000000;
  73.         call = 0;
  74.         return;
  75.     }
  76.     if (call == 10 && (level & 0b01000000) == 0b01000000)   //Decrementando a prioridade
  77.     {
  78.         if (((level & 0b10111111) >> (level+1)) != 0)
  79.         level &= 0b10111111;
  80.         level |= 0b10000000;
  81.         level >>= 1;
  82.         if (((level & 0b10111111) >> (level + 1)) != 0)
  83.             level &= 0b10111111;
  84.         call = 0;
  85.         return;
  86.     }
  87. }
  88. void Process::setSlice(unsigned time)
  89. {
  90.     if (estado == BLOQUEADO || estado == EM_EXECUCAO) return;
  91.     if (estado == EM_ESPERA)
  92.     {
  93.         if (read == -1)
  94.             read = time;
  95.         call++;
  96.         slice--;
  97.         estado = slice == 0 ? MORTO : EM_EXECUCAO;
  98.     }
  99. }
  100. void Process::setDuration()
  101. {
  102.     if (estado != FINISH || read != -1)
  103.         duration++;
  104. }
  105. void Process::setChange(unsigned memory, unsigned totalMemory)
  106. {
  107.     estado = estado == EM_ESPERA ? BLOQUEADO : estado;
  108.     estado = estado == EM_EXECUCAO ? EM_ESPERA : estado;
  109.     estado = this->memory <= totalMemory - memory && estado == BLOQUEADO ? PRONTO : estado;
  110. }
  111. bool Process::end()
  112. {
  113.     if (estado == FINISH)
  114.         return false;
  115.     estado = estado == MORTO ? FINISH : estado;
  116.     return estado == FINISH ? true : false;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement