Commit 3c614480 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Scheduler: ensure correct order of scheduleImmediately()-events

parent 2df7fcd8
......@@ -494,6 +494,10 @@ public class Scheduler implements EventHandler,
protected final Object data;
protected long simTime;
protected long globalOrderIdx;
protected static long globalOrderCounter = 0;
protected SchedulerEvent(Object data, long simTime,
EventHandler handler, int type) {
......@@ -507,6 +511,7 @@ public class Scheduler implements EventHandler,
this.handler = handler;
this.simTime = simTime;
this.type = type;
this.globalOrderIdx = ++globalOrderCounter;
}
public long getSimulationTime() {
......@@ -514,7 +519,8 @@ public class Scheduler implements EventHandler,
}
public int compareTo(SchedulerEvent o) {
return Double.compare(this.simTime, o.simTime);
int comp = Double.compare(this.simTime, o.simTime);
return comp == 0 ? Double.compare(this.globalOrderIdx, o.globalOrderIdx) : comp;
}
}
......@@ -595,11 +601,8 @@ public class Scheduler implements EventHandler,
@Override
public int compare(SchedulerEvent o1, SchedulerEvent o2) {
if (o1.getSimulationTime() > o2.getSimulationTime()) {
return 1;
} else {
return -1;
}
int comp = Double.compare(o1.simTime, o2.simTime);
return (comp == 0 ? Double.compare(o1.globalOrderIdx, o2.globalOrderIdx) : comp);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment