diff --git a/src/Global.java b/src/Global.java index cdfbff6ffbe1d9e8fb295155aa3f1e26c61aa375..881fc987be9642fe7d67f8fbf6875430e35648c3 100644 --- a/src/Global.java +++ b/src/Global.java @@ -21,7 +21,7 @@ public class Global { public void tick() { 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(); rr.tick(); diff --git a/src/Main.java b/src/Main.java index af2754916096a14d91c664b8f04bc3c040715483..34de52fd6e426882adf54874fabcd5899fbd9fe0 100644 --- a/src/Main.java +++ b/src/Main.java @@ -63,10 +63,9 @@ public class Main { scheduler.tick(); } - - //writing output //-------------- + System.out.println(scheduler.history); System.out.print(runningTasks.get(0).name + ":" + runningTasks.get(0).getWaitingTime()); diff --git a/src/RR.java b/src/RR.java index a1595f808d76ba838363496ecaae1fedba0a0b2b..a994fa8911f0a79f5b49fad4b382bef959eddb40 100644 --- a/src/RR.java +++ b/src/RR.java @@ -16,16 +16,28 @@ public class RR { private ArrayDeque<Task> waitingQueue = new ArrayDeque<>(); //inactive tasks 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) { this.global = global; } + /** + * Get back the right of scheduling tasks + */ public void start() { enabled = true; } + /** + * lose the right of scheduling tasks (e.g. because a higher priority task came in) + */ public void stop() { enabled = false; + + //forcing the active task to sleep runningFor = 0; if (activeTask != null) waitingQueue.addLast(activeTask); activeTask = null; @@ -39,8 +51,7 @@ public class RR { * signals a processor tick */ public void tick() { - if(!enabled) { - //System.out.println("Running RR: " + ((activeTask == null) ? "null" : activeTask.name)); + if(!enabled) { //if not enabled, every task waits if (activeTask != null) activeTask.waitOne(); for(Task t : waitingQueue) t.waitOne(); return; @@ -59,9 +70,7 @@ public class RR { runningFor = 0; } - if (runningFor == timeSlice) runningFor = 0; - - //System.out.println("Running RR: " + ((activeTask == null) ? "null" : activeTask.name)); + if (runningFor == timeSlice) runningFor = 0; //resetting runningFor even without swapping so that we will detect the next occasion when the time slice is over //registering time flow for(Task t : waitingQueue) t.waitOne(); @@ -76,10 +85,4 @@ public class RR { return activeTask==null && waitingQueue.size()==0; } - private String wqs() { - String ret = ""; - for(Task t : waitingQueue) ret += t.name; - return ret; - } - } diff --git a/src/SRTF.java b/src/SRTF.java index 1de7fd5a2d9cf88430a1426bedf05d904910c25f..57a9337b94b58f9a024bde4084ef84ce55907949 100644 --- a/src/SRTF.java +++ b/src/SRTF.java @@ -12,6 +12,10 @@ public class SRTF { 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) { this.global = global; } @@ -45,8 +49,6 @@ public class SRTF { needSwap = false; } - //System.out.print("SRTF interrupt: " + activeTask.name + " "); - //registering time flowing for(Task t : waitingQueue) t.waitOne(); activeTask.runOne();