mirror of
https://github.com/Comp211-SP24/lab-06-Rushilwiz.git
synced 2025-04-09 22:40:15 -04:00
fixed pq
This commit is contained in:
parent
e2e57a4fe7
commit
659e46ef30
27
schedule.c
27
schedule.c
|
@ -20,23 +20,32 @@ 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:
|
||||||
|
* - 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) {
|
void priority_queue(unsigned int quantum) {
|
||||||
min_heapify();
|
while(get_task(0) != NULL) {
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
min_heapify();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user