Advertisement
madegoff

RR_richtig

Jun 15th, 2023 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 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){ // der laufende prozess zuende
  11.  
  12.         if (RR_queue!=NULL){
  13.         running_process=queue_poll(RR_queue);
  14.         l_quantum = g_quantum;
  15.  
  16.         }
  17.     }
  18.  
  19.     if (l_quantum == 0){
  20.  
  21.         queue_add(running_process, RR_queue);
  22.         running_process = queue_poll(RR_queue);
  23.         l_quantum = g_quantum;
  24.     }
  25.  
  26.     if (running_process!=NULL){
  27.  
  28.         running_process->time_left--;
  29.         l_quantum--;
  30.     }
  31.  
  32.     return running_process;
  33. }
  34.  
  35. int RR_startup(int quantum){
  36.  
  37.     g_quantum = quantum;
  38.     l_quantum = quantum;
  39.  
  40.     RR_queue=new_queue();
  41.     if (RR_queue==NULL){
  42.         return 1;
  43.     }
  44.     return 0;
  45. }
  46.  
  47.  
  48. process* RR_new_arrival(process* arriving_process, process* running_process){
  49.  
  50.     if(arriving_process!=NULL){
  51.         queue_add(arriving_process, RR_queue);
  52.     }
  53.     return running_process;
  54. }
  55.  
  56.  
  57. void RR_finish(){
  58.  
  59.     free_queue(RR_queue);
  60. }
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement