From 75f2254bd68620e5faa5e48f5949e4bd5a6430db Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Fri, 21 Jun 2019 14:13:57 +0200 Subject: [PATCH] Made LogicExecuter robust against crashes in Timeline.executeUntil --- .../net/mograsim/logic/ui/LogicExecuter.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicExecuter.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicExecuter.java index fadfbe94..eb8a7235 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicExecuter.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicExecuter.java @@ -31,30 +31,36 @@ public class LogicExecuter { isRunningLive.notify(); } - while (shouldBeRunningLive.get()) + try { - // always execute to keep timeline from "hanging behind" for too long - long current = System.currentTimeMillis(); - timeline.executeUntil(timeline.laterThan(current), current + 10); - long sleepTime; - if (timeline.hasNext()) - sleepTime = timeline.nextEventTime() - current; - else - sleepTime = 10000; - try + while (shouldBeRunningLive.get()) { - nextExecSimulTime.set(current + sleepTime); - if (sleepTime > 0) - Thread.sleep(sleepTime); - } - catch (@SuppressWarnings("unused") InterruptedException e) - {// do nothing; it is normal execution flow to be interrupted + // always execute to keep timeline from "hanging behind" for too long + long current = System.currentTimeMillis(); + timeline.executeUntil(timeline.laterThan(current), current + 10); + long sleepTime; + if (timeline.hasNext()) + sleepTime = timeline.nextEventTime() - current; + else + sleepTime = 10000; + try + { + nextExecSimulTime.set(current + sleepTime); + if (sleepTime > 0) + Thread.sleep(sleepTime); + } + catch (@SuppressWarnings("unused") InterruptedException e) + {// do nothing; it is normal execution flow to be interrupted + } } } - isRunningLive.set(false); - synchronized (isRunningLive) + finally { - isRunningLive.notify(); + isRunningLive.set(false); + synchronized (isRunningLive) + { + isRunningLive.notify(); + } } }); timeline.addEventAddedListener(event -> -- 2.17.1