This commit is contained in:
Rushil Umaretiya 2024-04-18 03:20:21 -04:00
parent 55bea7a247
commit e00d6cab27
No known key found for this signature in database
GPG Key ID: 4E8FAF9C926AF959

View File

@ -20,43 +20,44 @@ void run_with_quantum(task_struct* task, unsigned int quantum) {
} }
} }
void fcfs() { void fcfs() {
while (get_task(0) != NULL) { while (get_task(0) != NULL) {
run_to_completion(remove_task(get_task(0)->pid)); run_to_completion(remove_task(get_task(0)->pid));
} }
} }
/** /**
* While the queue is not empty: * While the queue is not empty:
* - Min heapify the linked list. * - Min heapify the linked list.
* - Get the highest priority task from the list (the one at the head). * - Get the highest priority task from the list (the one at the head).
* - Remove and run the highest priority task for the given quantum. * - Remove and run the highest priority task for the given quantum.
* - If the task is not complete, then append it to the linked list. * - If the task is not complete, then append it to the linked list.
*/ */
void priority_queue(unsigned int quantum) { void priority_queue(unsigned int quantum) {
while(get_task(0) != NULL) { while (get_task(0) != NULL) {
if (size() > 1) if (size() > 1)
min_heapify(); min_heapify();
task_struct *task = remove_task(get_task(0)->pid); task_struct* task = remove_task(get_task(0)->pid);
run_with_quantum(task, quantum); run_with_quantum(task, quantum);
if (task->remaining_cycles != 0) if (task->remaining_cycles != 0) {
{
append_task(task->pid, task->priority, task->remaining_cycles); append_task(task->pid, task->priority, task->remaining_cycles);
} }
if (size() > 1)
min_heapify();
} }
} }
void round_robin(unsigned int quantum) { void round_robin(unsigned int quantum) {
while (get_task(0) != NULL) { while (size() > 0) {
task_struct* task = get_task(1 % size()); for (unsigned int i = 0; i < size(); i++) {
run_with_quantum(task, quantum); task_struct* task = get_task(i % size());
if (task->remaining_cycles == 0) { run_with_quantum(task, quantum);
remove_task(task->pid); if (task->remaining_cycles == 0) {
remove_task(task->pid);
}
} }
} }
} }