Skip to content
Snippets Groups Projects
Commit 5708fad3 authored by sfphoton's avatar sfphoton
Browse files

Skeleton with the easier function bodies done

parent 0ea34ee7
Branches
No related tags found
No related merge requests found
/**
* the global scheduler
* It will distribute the incoming tasks between the two schedulers (RR & SRTF) and select which one may determine the active task
*/
public class Global {
private SRTF srtf = new SRTF(); //high priority scheduler
private RR rr = new RR(); //low priority scheduler
String history = ""; //a string with tha names of task that have taken control so far - I will use this only for the output
public void add(Task t) {
if (t.isKernel)
srtf.add(t);
else
rr.add(t);
}
public void tick() {
}
/**
* A task is forcibly taking control
* @param t the task to be run
*/
public void changeRunning(Task t) {
}
}
import java.util.PriorityQueue;
import java.util.Queue;
/**
* A round-robin scheduler designed for low priority tasks - so it can be stopped when a higher priority task comes in and restarted later.
*/
public class RR {
private static final int timeSlice = 2; //time in ticks while a task is allowed to run
private int runningFor = 0; //the number of timeslices the active task has been running for
private Queue<Task> waitingQueue = new PriorityQueue<>(); //inactive tasks
private Task activeTask; //the active task; null if there are none
public void start() {
}
public void stop() {
}
public void add(Task t) {
waitingQueue.add(t);
}
/**
* signals a processor tick
*/
public void tick() {
}
}
import java.util.PriorityQueue;
import java.util.Queue;
/**
* An SRTF (shortest remaining time first) scheduler designed for high priority tasks
*/
public class SRTF {
private Queue<Task> waitingQueue = new PriorityQueue<>(); //inactive tasks
private Task activeTask; //active task; null if there are none
public void add(Task t) {
waitingQueue.add(t);
}
/**
* signals a processor tick
*/
public void tick() {
}
}
/**
* A task to be scheduled in the model
*/
public class Task {
public final char name;
public final boolean isKernel;
public final int startTime;
public int remainingTime;
private int waitingTime = 0;
public Task(char name, boolean isKernel, int start, int duration) {
this.name = name;
startTime = start;
remainingTime = duration;
this.isKernel = isKernel;
}
/**
* makes the task wait for one tick
*/
public void waitOne() {waitingTime++;}
public int getWaitingTime() {
return waitingTime;
}
/**
* makes the task run for one tick
*/
public void runOne() {remainingTime--;}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment