Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "PRIONP.h"
- #include <stdio.h>
- static queue_object* PRIONP_queue;
- //You can add more global variables here
- void* poll_highest_prio(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 prio = 0;
- 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 *cur_process = current_el->object;
- if(cur_process->priority > prio){
- prio = cur_process->priority;
- 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* PRIONP_tick (process* running_process){
- if (running_process == NULL){ //den ersten prozess aus der schlange nehmen
- running_process = queue_poll(PRIONP_queue);
- }
- if( running_process->time_left==0){
- running_process = poll_highest_prio(PRIONP_queue);
- }
- if (running_process != NULL){
- running_process->time_left--;
- }
- return running_process;
- }
- int PRIONP_startup(){
- PRIONP_queue=new_queue();
- if (PRIONP_queue==NULL){
- return 1;
- }
- return 0;
- }
- process* PRIONP_new_arrival(process* arriving_process, process* running_process){
- if(arriving_process!=NULL){
- queue_add(arriving_process, PRIONP_queue);
- }
- return running_process;
- }
- void PRIONP_finish(){
- free(PRIONP_queue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement