From 659e46ef304157842263db5de23f3c413f7e5dc1 Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Thu, 18 Apr 2024 02:52:29 -0400 Subject: [PATCH] fixed pq --- out.txt | 0 schedule.c | 27 ++++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) delete mode 100644 out.txt diff --git a/out.txt b/out.txt deleted file mode 100644 index e69de29..0000000 diff --git a/schedule.c b/schedule.c index befb009..7b09d31 100644 --- a/schedule.c +++ b/schedule.c @@ -20,23 +20,32 @@ void run_with_quantum(task_struct* task, unsigned int quantum) { } } + void fcfs() { while (get_task(0) != NULL) { run_to_completion(remove_task(get_task(0)->pid)); } } + +/** + * While the queue is not empty: + * - Min heapify the linked list. + * - Get the highest priority task from the list (the one at the head). + * - Remove and run the highest priority task for the given quantum. + * - If the task is not complete, then append it to the linked list. +*/ + void priority_queue(unsigned int quantum) { - min_heapify(); - - while (get_task(0) != NULL) { - task_struct* task = get_task(0); - run_with_quantum(task, quantum); - if (task->remaining_cycles > 0) { - remove_task(task->pid); - } - + while(get_task(0) != NULL) { min_heapify(); + task_struct *task = remove_task(get_task(0)->pid); + + run_with_quantum(task, quantum); + if (task->remaining_cycles != 0) + { + append_task(task->pid, task->priority, task->remaining_cycles); + } } }