From aaa234e27801b638ead157a56e5555073d20bd83 Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Wed, 16 May 2018 00:40:40 -0500 Subject: [PATCH] Tweak startup behavior to prevent deadlocks on startup --- .../src/main/java/jace/LawlessLegends.java | 6 +++--- .../src/main/java/jace/core/Motherboard.java | 8 +++---- .../src/main/java/jace/core/TimedDevice.java | 21 ++++++++++--------- .../java/jace/lawless/LawlessComputer.java | 3 +-- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Platform/Apple/tools/jace/src/main/java/jace/LawlessLegends.java b/Platform/Apple/tools/jace/src/main/java/jace/LawlessLegends.java index d496a234..cd2726ce 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/LawlessLegends.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/LawlessLegends.java @@ -131,12 +131,12 @@ public class LawlessLegends extends Application { observe(RAMEvent.TYPE.EXECUTE, 0x0c700, (e) -> { romStarted = true; }); - Emulator.computer.coldStart(); + Emulator.computer.invokeColdStart(); try { - Thread.sleep(10000); + Thread.sleep(7500); if (!romStarted) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Boot not detected, performing a cold start"); - Emulator.computer.coldStart(); + Emulator.computer.invokeColdStart(); } } catch (InterruptedException ex) { Logger.getLogger(LawlessLegends.class.getName()).log(Level.SEVERE, null, ex); diff --git a/Platform/Apple/tools/jace/src/main/java/jace/core/Motherboard.java b/Platform/Apple/tools/jace/src/main/java/jace/core/Motherboard.java index 26d3ecd9..2111cfa1 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/core/Motherboard.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/core/Motherboard.java @@ -40,7 +40,7 @@ import java.util.logging.Logger; * @author Brendan Robert (BLuRry) brendan.robert@gmail.com */ public class Motherboard extends TimedDevice { - + final public Set miscDevices = Collections.synchronizedSet(new LinkedHashSet<>()); @ConfigurableField(name = "Enable Speaker", shortName = "speaker", defaultValue = "true") public static boolean enableSpeaker = true; @@ -97,11 +97,9 @@ public class Motherboard extends TimedDevice { clockCounter = cpuPerClock; computer.getVideo().doTick(); for (Optional card : cards) { - card.ifPresent(c -> c.doTick()); + card.ifPresent(Card::doTick); } - miscDevices.stream().forEach((m) -> { - m.doTick(); - }); + miscDevices.forEach(Device::doTick); } catch (Throwable t) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, t); } diff --git a/Platform/Apple/tools/jace/src/main/java/jace/core/TimedDevice.java b/Platform/Apple/tools/jace/src/main/java/jace/core/TimedDevice.java index a0050962..c4866c4b 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/core/TimedDevice.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/core/TimedDevice.java @@ -58,10 +58,11 @@ public abstract class TimedDevice extends Device { public boolean suspend() { disableTempMaxSpeed(); boolean result = super.suspend(); - if (worker != null && worker.isAlive()) { + Thread w = worker; + if (w != null && w.isAlive()) { try { - worker.interrupt(); - worker.join(1000); + w.interrupt(); + w.join(1000); } catch (InterruptedException ex) { } } @@ -118,22 +119,22 @@ public abstract class TimedDevice extends Device { public final int getSpeedRatio() { return speedRatio; } - + public final void setMaxSpeed(boolean enabled) { maxspeed = enabled; if (!enabled) { disableTempMaxSpeed(); } } - + public final boolean isMaxSpeed() { return maxspeed; } - + public final long getSpeedInHz() { return cyclesPerInterval * 100L; } - + public final void setSpeedInHz(long cyclesPerSecond) { // System.out.println("Raw set speed for " + getName() + " to " + cyclesPerSecond + "hz"); speedRatio = (int) Math.round(cyclesPerSecond * 100.0 / defaultCyclesPerSecond()); @@ -143,16 +144,16 @@ public abstract class TimedDevice extends Device { cycleTimer = 0; resetSyncTimer(); } - + public final void setSpeedInPercentage(int ratio) { // System.out.println("Setting " + getName() + " speed ratio to " + speedRatio); cyclesPerSecond = defaultCyclesPerSecond() * ratio / 100; if (cyclesPerSecond == 0) { cyclesPerSecond = defaultCyclesPerSecond(); } - setSpeedInHz(cyclesPerSecond); + setSpeedInHz(cyclesPerSecond); } - + long skip = 0; long wait = 0; diff --git a/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessComputer.java b/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessComputer.java index 69fa11ea..0717fa0c 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessComputer.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessComputer.java @@ -169,9 +169,8 @@ public class LawlessComputer extends Apple2e { try { for (Optional c : getMemory().getAllCards()) { c.ifPresent(Card::reset); - waitForVBL(); } - getCpu().resume(); + waitForVBL(); reboot(); } catch (InterruptedException ex) { Logger.getLogger(LawlessComputer.class.getName()).log(Level.SEVERE, null, ex);