diff --git a/schedule.c b/schedule.c index 04a631e..7bf4bbb 100644 --- a/schedule.c +++ b/schedule.c @@ -20,43 +20,44 @@ 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) { - while(get_task(0) != NULL) { + while (get_task(0) != NULL) { if (size() > 1) 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); - if (task->remaining_cycles != 0) - { + if (task->remaining_cycles != 0) { append_task(task->pid, task->priority, task->remaining_cycles); } + + if (size() > 1) + min_heapify(); } } void round_robin(unsigned int quantum) { - while (get_task(0) != NULL) { - task_struct* task = get_task(1 % size()); - run_with_quantum(task, quantum); - if (task->remaining_cycles == 0) { - remove_task(task->pid); + while (size() > 0) { + for (unsigned int i = 0; i < size(); i++) { + task_struct* task = get_task(i % size()); + run_with_quantum(task, quantum); + if (task->remaining_cycles == 0) { + remove_task(task->pid); + } } } }