|
|
@@ -0,0 +1,63 @@
|
|
|
+package benchmarks;
|
|
|
+
|
|
|
+import xdevs.core.modeling.Atomic;
|
|
|
+import xdevs.core.modeling.Port;
|
|
|
+import xdevs.core.examples.devstone.Dhrystone;
|
|
|
+
|
|
|
+public class DelayedAtomic extends Atomic {
|
|
|
+ private enum STATE {Passive, Active}
|
|
|
+
|
|
|
+ public Port<Integer> iIn = new Port<>("i_in");
|
|
|
+ public Port<Integer> oOut;
|
|
|
+
|
|
|
+ protected STATE state = Passive
|
|
|
+ protected double preparationTime, intDelay, extDelay;
|
|
|
+ protected boolean hasOutPort, stats;
|
|
|
+ public long intCount = 0, extCount = 0;
|
|
|
+
|
|
|
+ public DelayedAtomic(String name, double prepTime, double intDelay, double extDelay, boolean hasOutPort, boolean stats) {
|
|
|
+ super(name);
|
|
|
+ this.preparationTime = prepTime;
|
|
|
+ this.intDelay = intDelay;
|
|
|
+ this.extDelay = extDelay;
|
|
|
+ this.hasOutPort = hasOutPort;
|
|
|
+ this.stats = stats;
|
|
|
+
|
|
|
+ super.addInPort(iIn);
|
|
|
+ if (hasOutPort) {
|
|
|
+ this.oOut = new Port<>("o_out");
|
|
|
+ super.addOutPort(oOut);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initialize() {
|
|
|
+ super.passivate();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deltint() {
|
|
|
+ if (stats) intCount++;
|
|
|
+
|
|
|
+ if (intDelay > 0.0) Dhrystone.execute(intDelay);
|
|
|
+
|
|
|
+ super.passivate();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deltext(double e) {
|
|
|
+ super.resume(e);
|
|
|
+ if (stats) extCount++;
|
|
|
+
|
|
|
+ if (extDelay > 0.0) Dhrystone.execute(extDelay);
|
|
|
+
|
|
|
+ super.holdIn(STATE.Active, preparationTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void lambda() {
|
|
|
+ if (hasOutPort) {
|
|
|
+ oOut.addValue(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|