]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fix management of scheduledAt in AbstractActionContext 35/4635/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Fri, 8 Jan 2021 08:02:16 +0000 (10:02 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Fri, 8 Jan 2021 11:11:01 +0000 (13:11 +0200)
gitlab #666

Change-Id: I1c251c99a99302eb765fb7bb2c6be383fe417573

bundles/org.simantics.simulation.sequences/src/org/simantics/simulation/sequences/action/AbstractActionContext.java

index 1187230ad12f4780914797193e4045ac613810ef..5b5917f6ab33d3b016bd685ad0d391dfcb58f8a4 100644 (file)
@@ -76,7 +76,7 @@ public abstract class AbstractActionContext implements ActionContext {
 
     public boolean isStopped() {
        synchronized (this) {
-               return stopped || (scheduledNextStep.isEmpty() && scheduledAt.isEmpty());
+               return stopped;
        }
     }
     
@@ -96,7 +96,6 @@ public abstract class AbstractActionContext implements ActionContext {
                SCLContext context = SCLContext.getCurrent();
                Object oldActionContext = context.put("sequenceAction", this);
                try {
-                   Task firstTask = scheduledAt.peek();
                    while(true) {
                        while(!scheduledNow.isEmpty()) {
                                try {
@@ -109,16 +108,16 @@ public abstract class AbstractActionContext implements ActionContext {
                                        this.exceptions.add(new RuntimeException("Action failure at " + currentTime + ": " + e.getMessage(), e));
                                }
                        }
-                       if(firstTask == null)
+                       Task firstTask = scheduledAt.peek();
+                       if(firstTask == null) {
+                           if (scheduledNextStep.isEmpty())
+                               stopped = true;
                            return Double.POSITIVE_INFINITY;
-                       else if(firstTask.time > currentTime+TIME_TOLERANCE)
+                       } else if(firstTask.time > currentTime+TIME_TOLERANCE) {
                            return firstTask.time;
-                       else {
+                       } else {
+                           scheduledAt.remove();
                            firstTask.continuation.apply(Tuple0.INSTANCE);
-                               synchronized (this) {
-                                       scheduledAt.remove();
-                               }
-                           firstTask = scheduledAt.peek();
                        }
                    }
                } finally {