mirror of
https://github.com/Comp211-SP24/lab-06-Rushilwiz.git
synced 2025-04-09 22:40:15 -04:00
finished?
This commit is contained in:
parent
8ff32c5e8d
commit
aca8171c39
35
schedule.c
35
schedule.c
|
@ -6,21 +6,46 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void run_to_completion(task_struct* task) {
|
void run_to_completion(task_struct* task) {
|
||||||
// TODO:
|
printf("Task %d ran for %d cycle(s).\n", task->pid, task->remaining_cycles);
|
||||||
|
task->remaining_cycles = 0;
|
||||||
|
printf("Task %d completed.\n", task->pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_with_quantum(task_struct* task, unsigned int quantum) {
|
void run_with_quantum(task_struct* task, unsigned int quantum) {
|
||||||
// TODO:
|
if (task->remaining_cycles <= quantum) {
|
||||||
|
run_to_completion(task);
|
||||||
|
} else {
|
||||||
|
printf("Task %d ran for %d cycle(s).\n", task->pid, quantum);
|
||||||
|
task->remaining_cycles -= quantum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fcfs() {
|
void fcfs() {
|
||||||
// TODO:
|
while (get_task(0) != NULL) {
|
||||||
|
run_to_completion(remove_task(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void priority_queue(unsigned int quantum) {
|
void priority_queue(unsigned int quantum) {
|
||||||
// TODO:
|
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(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
min_heapify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void round_robin(unsigned int quantum) {
|
void round_robin(unsigned int quantum) {
|
||||||
// TODO:
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user