Skip to content
Snippets Groups Projects
Commit 0ea98fa9 authored by sfphoton's avatar sfphoton
Browse files

Refactoring, commenting

parent 08617608
Branches
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ public class Global { ...@@ -21,7 +21,7 @@ public class Global {
public void tick() { public void tick() {
if(srtf.isEmpty() && rr.isEmpty()) {Main.schedulersEmpty = true; return;} if(srtf.isEmpty() && rr.isEmpty()) {Main.schedulersEmpty = true; return;}
else if(!srtf.isEmpty()) rr.stop(); else if(!srtf.isEmpty()) rr.stop(); //if there is a high priority task, we will choose that and not let the low priority scheduler work
srtf.tick(); srtf.tick();
rr.tick(); rr.tick();
......
...@@ -63,10 +63,9 @@ public class Main { ...@@ -63,10 +63,9 @@ public class Main {
scheduler.tick(); scheduler.tick();
} }
//writing output //writing output
//-------------- //--------------
System.out.println(scheduler.history); System.out.println(scheduler.history);
System.out.print(runningTasks.get(0).name + ":" + runningTasks.get(0).getWaitingTime()); System.out.print(runningTasks.get(0).name + ":" + runningTasks.get(0).getWaitingTime());
......
...@@ -16,16 +16,28 @@ public class RR { ...@@ -16,16 +16,28 @@ public class RR {
private ArrayDeque<Task> waitingQueue = new ArrayDeque<>(); //inactive tasks private ArrayDeque<Task> waitingQueue = new ArrayDeque<>(); //inactive tasks
private Task activeTask = null; //the active task; null if there are none private Task activeTask = null; //the active task; null if there are none
/**
* Constructor
* @param global the multilevel scheduler to which this one belongs
*/
public RR(Global global) { public RR(Global global) {
this.global = global; this.global = global;
} }
/**
* Get back the right of scheduling tasks
*/
public void start() { public void start() {
enabled = true; enabled = true;
} }
/**
* lose the right of scheduling tasks (e.g. because a higher priority task came in)
*/
public void stop() { public void stop() {
enabled = false; enabled = false;
//forcing the active task to sleep
runningFor = 0; runningFor = 0;
if (activeTask != null) waitingQueue.addLast(activeTask); if (activeTask != null) waitingQueue.addLast(activeTask);
activeTask = null; activeTask = null;
...@@ -39,8 +51,7 @@ public class RR { ...@@ -39,8 +51,7 @@ public class RR {
* signals a processor tick * signals a processor tick
*/ */
public void tick() { public void tick() {
if(!enabled) { if(!enabled) { //if not enabled, every task waits
//System.out.println("Running RR: " + ((activeTask == null) ? "null" : activeTask.name));
if (activeTask != null) activeTask.waitOne(); if (activeTask != null) activeTask.waitOne();
for(Task t : waitingQueue) t.waitOne(); for(Task t : waitingQueue) t.waitOne();
return; return;
...@@ -59,9 +70,7 @@ public class RR { ...@@ -59,9 +70,7 @@ public class RR {
runningFor = 0; runningFor = 0;
} }
if (runningFor == timeSlice) runningFor = 0; if (runningFor == timeSlice) runningFor = 0; //resetting runningFor even without swapping so that we will detect the next occasion when the time slice is over
//System.out.println("Running RR: " + ((activeTask == null) ? "null" : activeTask.name));
//registering time flow //registering time flow
for(Task t : waitingQueue) t.waitOne(); for(Task t : waitingQueue) t.waitOne();
...@@ -76,10 +85,4 @@ public class RR { ...@@ -76,10 +85,4 @@ public class RR {
return activeTask==null && waitingQueue.size()==0; return activeTask==null && waitingQueue.size()==0;
} }
private String wqs() {
String ret = "";
for(Task t : waitingQueue) ret += t.name;
return ret;
}
} }
...@@ -12,6 +12,10 @@ public class SRTF { ...@@ -12,6 +12,10 @@ public class SRTF {
private boolean needSwap = true; //stores if the active task should be changed private boolean needSwap = true; //stores if the active task should be changed
/**
* constructor
* @param global the multilevel scheduler to which this one belongs
*/
public SRTF(Global global) { public SRTF(Global global) {
this.global = global; this.global = global;
} }
...@@ -45,8 +49,6 @@ public class SRTF { ...@@ -45,8 +49,6 @@ public class SRTF {
needSwap = false; needSwap = false;
} }
//System.out.print("SRTF interrupt: " + activeTask.name + " ");
//registering time flowing //registering time flowing
for(Task t : waitingQueue) t.waitOne(); for(Task t : waitingQueue) t.waitOne();
activeTask.runOne(); activeTask.runOne();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment