From f258d5f93205980be7c504ea9201596e4005dcec Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Sat, 7 Aug 2021 08:15:09 -0400 Subject: [PATCH] Locking & Thread fixes --- .../volmit/iris/util/parallel/HyperLock.java | 42 +++++++++++++++++-- .../volmit/iris/util/parallel/MultiBurst.java | 9 +++- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/parallel/HyperLock.java b/src/main/java/com/volmit/iris/util/parallel/HyperLock.java index fc7bcbc4a..7af994b2b 100644 --- a/src/main/java/com/volmit/iris/util/parallel/HyperLock.java +++ b/src/main/java/com/volmit/iris/util/parallel/HyperLock.java @@ -64,14 +64,48 @@ public class HyperLock { public void withNasty(int x, int z, NastyRunnable r) throws Throwable { lock(x, z); - r.run(); - unlock(x, z); + Throwable ee = null; + try { + r.run(); + } + + catch(Throwable e) + { + ee = e; + } + + finally + { + unlock(x, z); + + if(ee != null) + { + throw ee; + } + } } public void withIO(int x, int z, IORunnable r) throws IOException { lock(x, z); - r.run(); - unlock(x, z); + IOException ee = null; + try { + r.run(); + } + + catch(IOException e) + { + ee = e; + } + + finally + { + unlock(x, z); + + if(ee != null) + { + throw ee; + } + } } public T withResult(int x, int z, Supplier r) { diff --git a/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java b/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java index 4e69de674..99dc91627 100644 --- a/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java +++ b/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java @@ -27,6 +27,7 @@ import com.volmit.iris.util.scheduling.Looper; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Supplier; public class MultiBurst { public static final MultiBurst burst = new MultiBurst("Iris", IrisSettings.get().getConcurrency().getMiscThreadPriority(), IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getMiscThreadCount())); @@ -53,13 +54,13 @@ public class MultiBurst { if (M.ms() - last.get() > TimeUnit.MINUTES.toMillis(1) && service != null) { service.shutdown(); service = null; - Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resource."); + Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resources."); } return 60000; } }; - heartbeat.setName(name); + heartbeat.setName(name + " Monitor"); heartbeat.start(); } @@ -123,6 +124,10 @@ public class MultiBurst { return CompletableFuture.runAsync(o, getService()); } + public CompletableFuture completeValue(Supplier o) { + return CompletableFuture.supplyAsync(o, getService()); + } + public void shutdownNow() { Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + "."); heartbeat.interrupt();