Created
September 4, 2019 19:35
-
-
Save victoroliveirab/d22b7db96442e05999860f178fd028bb to your computer and use it in GitHub Desktop.
Round-Robin Implementation in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "task.h" | |
#include "list.h" | |
#include "cpu.h" | |
/* | |
Round-Robin Scheduling Algorithm Implementation | |
Programming Project of Chapter 5 from the book "Operating System Concepts - 10th Edition" | |
*/ | |
struct node * list = NULL; | |
void add(char *name, int priority, int burst) { | |
Task * task = (Task *)malloc(sizeof (Task)); | |
task->name = name; | |
task->priority = priority; | |
task->burst = burst; | |
task->tid = 0; | |
insert(&list, task); | |
} | |
void run_schedule(struct node * current) { | |
if (current) { | |
int slice = current->task->burst; | |
if (slice <= QUANTUM) { | |
run(current->task, slice); | |
delete(&list,current->task); | |
} | |
else { | |
run(current->task, QUANTUM); | |
current->task->burst -= QUANTUM; | |
struct node * tail = current; | |
struct node * temp = current->next; | |
while (temp) { | |
tail = temp; | |
temp = temp->next; | |
} | |
list = current->next; | |
current->next = NULL; | |
tail->next = current; | |
} | |
run_schedule(list); | |
} | |
} | |
void schedule() { | |
run_schedule(list); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment