From 324110209c41107aa2aa52927243b74b99a39665 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Fri, 8 Jan 2021 10:02:16 +0200 Subject: [PATCH] Fix management of scheduledAt in AbstractActionContext gitlab #666 Change-Id: I1c251c99a99302eb765fb7bb2c6be383fe417573 --- .../sequences/action/AbstractActionContext.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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 { -- 2.47.1