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

Bugfix: RR will now always check if swap is needed when the active task ran (another) 2 CPU cycles.

parent 7f607dcb
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ public class RR { ...@@ -13,7 +13,7 @@ public class RR {
private boolean enabled = true; private boolean enabled = true;
private Queue<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
public RR(Global global) { public RR(Global global) {
...@@ -27,12 +27,12 @@ public class RR { ...@@ -27,12 +27,12 @@ public class RR {
public void stop() { public void stop() {
enabled = false; enabled = false;
runningFor = 0; runningFor = 0;
if (activeTask != null) waitingQueue.add(activeTask); if (activeTask != null) waitingQueue.addLast(activeTask);
activeTask = null; activeTask = null;
} }
public void add(Task t) { public void add(Task t) {
waitingQueue.add(t); waitingQueue.addLast(t);
} }
/** /**
...@@ -51,14 +51,16 @@ public class RR { ...@@ -51,14 +51,16 @@ public class RR {
//swapping //swapping
if(waitingQueue.size() > 0 && (runningFor == timeSlice || activeTask == null)) { //we swap if we can and if we need to; we need to when the running period is over or the current task is not running anymore if(waitingQueue.size() > 0 && (runningFor == timeSlice || activeTask == null)) { //we swap if we can and if we need to; we need to when the running period is over or the current task is not running anymore
if (activeTask != null) waitingQueue.add(activeTask); if (activeTask != null) waitingQueue.addLast(activeTask);
activeTask = waitingQueue.remove(); activeTask = waitingQueue.removeFirst();
global.changeRunning(activeTask); global.changeRunning(activeTask);
runningFor = 0; runningFor = 0;
} }
if (runningFor == timeSlice) runningFor = 0;
//System.out.println("Running RR: " + ((activeTask == null) ? "null" : activeTask.name)); //System.out.println("Running RR: " + ((activeTask == null) ? "null" : activeTask.name));
//registering time flow //registering time flow
...@@ -74,4 +76,10 @@ public class RR { ...@@ -74,4 +76,10 @@ 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;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment