diff --git a/code/headers.h b/code/headers.h index 14976da..7f0dbbe 100644 --- a/code/headers.h +++ b/code/headers.h @@ -44,7 +44,7 @@ //=============================== // ARGUMENTS //=============================== -const int DEBUG = false; // set to true to enable debug prints +const int DEBUG = true; // set to true to enable debug prints const int DELAY = false; // set to true to add delay ///============================== diff --git a/code/minHeap.c b/code/minHeap.c index a9b509e..c35fd6d 100644 --- a/code/minHeap.c +++ b/code/minHeap.c @@ -1,6 +1,6 @@ #include "minHeap.h" -#include "headers.h" - +#include +#include /** * @comp: pass a function to be used to compare between any two heap elements return: @@ -24,20 +24,19 @@ min_heap *createMinHeap(int (*comp)(void *, void *)) { */ void insertMinHeap(min_heap** heap, void * element) { - if(DEBUG){ + // if(DEBUG){ printf("entered insertion safely\n"); printHeap((*heap)); - } + // } if((*heap)->size == (*heap)->capacity) (*heap) = *doubleCapacity((*heap)); + (*heap)->arr[(*heap)->size] = element; (*heap)->size++; - if(DEBUG) - printf("arr[%ld]: %d\n" , (*heap)->size-1 , (int*)(*heap)->arr[(*heap)->size-1]); - + decreaseKey((*heap) , (*heap)->size-1); } @@ -46,10 +45,10 @@ void insertMinHeap(min_heap** heap, void * element) */ void * extractMin(min_heap * heap) { - if(DEBUG){ + // if(DEBUG){ printf("entered extraction!!\n"); printHeap(heap); - } + // } void* minElement = heap->arr[0]; heap->size--; @@ -75,15 +74,6 @@ void decreaseKey(min_heap* heap ,int ind){ ind = parentInd; parentInd = (ind-1)/2; } - - void **arr = heap->arr; - int parentInd = (ind - 1) / 2; - - while (parentInd >= 0 && heap->compare(arr[parentInd], arr[ind]) > 0) { - swap(arr, ind, parentInd); - ind = parentInd; - parentInd = (ind - 1) / 2; - } } /** @@ -133,10 +123,10 @@ min_heap** doubleCapacity(min_heap *heap) min_heap** returnval = &newHeap; - if(DEBUG){ + // if(DEBUG){ printf("doubling occured!!\n"); printHeap(*returnval); - } + // } return returnval; } @@ -149,9 +139,7 @@ void swap(void **arr, int ind1, int ind2) { } void printHeap(min_heap *heap) { - printf("\n=============================\n"); - printf("capacity: %d \nsize: %d\narr:", (int)heap->capacity, (int)heap->size); - for (int i = 0; i < heap->capacity; i++) - printf("%d ", *(int *)heap->arr[i]); - printf("\n=============================\n\n"); + printf("=============================\n"); + printf("capacity: %d \nsize: %d\n", (int)heap->capacity, (int)heap->size); + printf("=============================\n"); } diff --git a/code/process_generator.c b/code/process_generator.c index 0447287..82da247 100644 --- a/code/process_generator.c +++ b/code/process_generator.c @@ -296,7 +296,7 @@ void sendProcessesToScheduler(queue *processes, int msgQID) { "priority: %d to scheduler\n" ANSI_RESET, process->id, process->AT, process->BT, process->priority); // TODO: check this initial values later - process->RT = process->BT; + //process->RT = process->BT; //this is set inside the scheduler (shmAdd) process->WT = 0; process->TA = 0; process->LST = currentTime; diff --git a/code/scheduler.c b/code/scheduler.c index 47773d6..b485079 100644 --- a/code/scheduler.c +++ b/code/scheduler.c @@ -184,8 +184,13 @@ int SRTNScheduling(void *readyQueue, process_t *process, int *rQuantem) { process_t *currentProcess; if (process) { - insertMinHeap(&readyQ, process); - currentProcess = (process_t *)getMin(readyQ); + insertMinHeap(&readyQ, (void*)process); + currentProcess = (process_t *)extractMin(readyQ); + + if(DEBUG) + printf("inside SRTN, RT = %d\n" , *(currentProcess->RT)); + fflush(stdout); + if (process == currentProcess) contextSwitch(); } @@ -313,8 +318,8 @@ process_t *createProcess(d_list *processTable, process_t *process) { int shmid = initSchProShm(pid); int* shmAdd = (int*)shmat(shmid , (void*)0 , 0); - pcb->process.RT = shmAdd; - *pcb->process.RT = process->BT; + processEntry->PCB.process->RT = shmAdd; + *processEntry->PCB.process->RT = process->BT; if (pid == -1) { perror("fork");