From: Reino Ruusu Date: Fri, 8 Jan 2021 08:02:16 +0000 (+0200) Subject: Fix management of scheduledAt in AbstractActionContext X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=324110209c41107aa2aa52927243b74b99a39665;p=simantics%2Fplatform.git Fix management of scheduledAt in AbstractActionContext gitlab #666 Change-Id: I1c251c99a99302eb765fb7bb2c6be383fe417573 --- diff --git a/bundles/org.simantics.simulation.sequences/src/org/simantics/simulation/sequences/action/AbstractActionContext.java b/bundles/org.simantics.simulation.sequences/src/org/simantics/simulation/sequences/action/AbstractActionContext.java index 1187230ad..5b5917f6a 100644 --- a/bundles/org.simantics.simulation.sequences/src/org/simantics/simulation/sequences/action/AbstractActionContext.java +++ b/bundles/org.simantics.simulation.sequences/src/org/simantics/simulation/sequences/action/AbstractActionContext.java @@ -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 {