Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SJN.h"
- static queue_object* SJN_queue;
- //You can add more global variables here
- void* poll_lowest_time(queue_object* queue){
- queue_object *prev_el = queue;
- queue_object *current_el = queue->next;
- queue_object *prev_old; //das element vor dem zu loeschenden element
- queue_object *old; //das zu loeschende element
- void* obj;
- int time = 100;
- if (current_el->next == NULL){ //ein element in der warteschlange
- queue->next = NULL;
- obj = current_el->object;
- free(current_el);
- }
- else{
- while(current_el!=NULL){
- process* current_process = current_el->object;
- int current_bedienzeit = current_process->time_left;
- if(current_bedienzeit < time){
- time = current_bedienzeit;
- prev_old = prev_el;
- old = current_el;
- }
- prev_el=prev_el->next;
- current_el=current_el->next;
- }
- obj = old->object;
- prev_old->next = old->next;
- free(old);
- }
- return obj;
- }
- process* SJN_tick (process* running_process){
- if (running_process == NULL){ //den ersten prozess aus der schlange nehmen
- running_process = queue_poll(SJN_queue);
- }
- if( running_process->time_left==0){
- running_process = poll_lowest_time(SJN_queue);
- }
- if (running_process != NULL){
- running_process->time_left--;
- }
- return running_process;
- }
- int SJN_startup(){
- SJN_queue=new_queue();
- if (SJN_queue==NULL){
- return 1;
- }
- return 0;
- }
- process* SJN_new_arrival(process* arriving_process, process* running_process){
- if(arriving_process!=NULL){
- queue_add(arriving_process, SJN_queue);
- }
- return running_process;
- }
- void SJN_finish(){
- free(SJN_queue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement