Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scheduler): fixed some bugs #16

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions code/minHeap.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void insertMinHeap(min_heap **heap, void *element) {
*/
void *extractMin(min_heap *heap) {
// if(DEBUG){
printf("entered extraction!!\n");
printHeap(heap);
// printf("entered extraction!!\n");
// printHeap(heap);
// }

void *minElement = heap->arr[0];
Expand All @@ -55,6 +55,15 @@ void *extractMin(min_heap *heap) {
return minElement;
}

/**
* get the min element in the heap
*/
void *getMin(min_heap *heap) {
if (!heap || heap->size <= 0)
return NULL;
return heap->arr[0];
}

/**
* Shift-up operation, called on decreasing the priority value
*/
Expand Down Expand Up @@ -119,7 +128,7 @@ min_heap **doubleCapacity(min_heap *heap) {
min_heap **returnval = &newHeap;

// if(DEBUG){
// printf("doubling occured!!\n");
// printf("doubling occurred!!\n");
// printHeap(*returnval);
// }

Expand Down
1 change: 1 addition & 0 deletions code/minHeapTest.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "minHeap.h"
#include <stdio.h>

int compare(void* a , void* b){

Expand Down
4 changes: 2 additions & 2 deletions code/process_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "process_generator.h"
#include "headers.h"
#include <math.h>
#include <string.h>

/**
Expand Down Expand Up @@ -317,12 +316,13 @@ 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; //this is set inside the scheduler (shmAdd)
process->WT = 0;
process->TA = 0;
process->LST = currentTime;
process->ST = -1;
process->FT = -1;
process->state = READY;
process->pid = 1;

response = msgsnd(msgQID, process, sizeof(process_t), !IPC_NOWAIT);
if (response == -1) {
Expand Down
6 changes: 3 additions & 3 deletions code/processes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#id arrival runtime priority
1 2 4 1
2 7 5 1
3 15 6 1
1 2 20 1
2 5 10 1
3 9 15 1
8 changes: 6 additions & 2 deletions code/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ void push(queue *q, void *item) {
* remove the first element from the queue
* @q: pointer to queue
*/
void pop(queue *q) {
void *pop(queue *q) {
d_node *n;

if (empty(q))
return;
return NULL;

n = getNode(q->list, 0);
deleteNodeStart(q->list);
return n->data;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion code/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ queue *createQueue(void (*free_func)(void *));
int empty(queue *q);
size_t size(queue *q);
void push(queue *q, void *item);
void pop(queue *q);
void *pop(queue *q);
void *front(queue *q);
void *back(queue *q);
void destroyQueue(queue *q);
Loading