Advertisement
madegoff

RR

Jun 15th, 2023 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #include "RR.h"
  2.  
  3. static queue_object* RR_queue;
  4. int g_quantum; //g steht fuer global
  5. int l_quantum; //local (wird geandert)
  6. //You can add more global variables
  7.  
  8. process* RR_tick (process* running_process){
  9.  
  10.     if (running_process==NULL || running_process->time_left==0){
  11.         running_process=queue_poll(RR_queue);
  12.     }
  13.     else{
  14.  
  15.         if (l_quantum != 0){
  16.  
  17.         running_process->time_left--;
  18.         l_quantum--;
  19.  
  20.         }
  21.         if (l_quantum == 0){
  22.  
  23.             queue_add(running_process, RR_queue);
  24.             l_quantum = g_quantum;
  25.             running_process = queue_poll(RR_queue);
  26.         }
  27.     }
  28.  
  29.     return running_process;
  30. }
  31.  
  32. int RR_startup(int quantum){
  33.  
  34.     g_quantum = quantum;
  35.     l_quantum = quantum;
  36.  
  37.     RR_queue=new_queue();
  38.     if (RR_queue==NULL){
  39.         return 1;
  40.     }
  41.     return 0;
  42. }
  43.  
  44.  
  45. process* RR_new_arrival(process* arriving_process, process* running_process){
  46.  
  47.     if(arriving_process!=NULL){
  48.         queue_add(arriving_process, RR_queue);
  49.     }
  50.     return running_process;
  51. }
  52.  
  53.  
  54. void RR_finish(){
  55.  
  56.     free_queue(RR_queue);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement