From 9e147774bdf29b087a14497d9cfd69a24db200d6 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Thu, 4 Sep 2025 13:54:28 +0200 Subject: [PATCH] revert mantle change to hopefully fix deadlock --- .../com/volmit/iris/util/mantle/Mantle.java | 66 +++++++++---------- .../iris/util/parallel/StreamUtils.java | 7 +- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/core/src/main/java/com/volmit/iris/util/mantle/Mantle.java index f795d4f14..3867a2fc8 100644 --- a/core/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/core/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -531,7 +531,7 @@ public class Mantle { try { if (!trim || !unload) { try { - return getSafe(x, z); + return getSafe(x, z).get(); } catch (Throwable e) { e.printStackTrace(); } @@ -546,7 +546,7 @@ public class Mantle { } try { - return getSafe(x, z); + return getSafe(x, z).get(); } catch (InterruptedException e) { Iris.warn("Failed to get Tectonic Plate " + x + " " + z + " Due to a thread intterruption (hotload?)"); Iris.reportError(e); @@ -575,8 +575,8 @@ public class Mantle { * @return the future of a tectonic plate. */ @RegionCoordinates - private TectonicPlate getSafe(int x, int z) throws Throwable { - return hyperLock.withNastyResult(x, z, () -> { + private Future getSafe(int x, int z) { + return ioBurst.completeValue(() -> hyperLock.withResult(x, z, () -> { Long k = key(x, z); use(k); TectonicPlate r = loadedRegions.get(k); @@ -584,43 +584,41 @@ public class Mantle { return r; } - return ioBurst.completeValue(() -> { - TectonicPlate region; - File file = fileForRegion(dataFolder, x, z); - if (file.exists()) { - try { - Iris.addPanic("reading.tectonic-plate", file.getAbsolutePath()); - region = worker.read(file.getName()); + TectonicPlate region; + File file = fileForRegion(dataFolder, x, z); + if (file.exists()) { + try { + Iris.addPanic("reading.tectonic-plate", file.getAbsolutePath()); + region = worker.read(file.getName()); - if (region.getX() != x || region.getZ() != z) { - Iris.warn("Loaded Tectonic Plate " + x + "," + z + " but read it as " + region.getX() + "," + region.getZ() + "... Assuming " + x + "," + z); - } - - loadedRegions.put(k, region); - Iris.debug("Loaded Tectonic Plate " + C.DARK_GREEN + x + " " + z + C.DARK_AQUA + " " + file.getName()); - } catch (Throwable e) { - Iris.error("Failed to read Tectonic Plate " + file.getAbsolutePath() + " creating a new chunk instead."); - Iris.reportError(e); - if (!(e instanceof EOFException)) { - e.printStackTrace(); - } - Iris.panic(); - region = new TectonicPlate(worldHeight, x, z); - loadedRegions.put(k, region); - Iris.debug("Created new Tectonic Plate (Due to Load Failure) " + C.DARK_GREEN + x + " " + z); + if (region.getX() != x || region.getZ() != z) { + Iris.warn("Loaded Tectonic Plate " + x + "," + z + " but read it as " + region.getX() + "," + region.getZ() + "... Assuming " + x + "," + z); } - use(k); - return region; + loadedRegions.put(k, region); + Iris.debug("Loaded Tectonic Plate " + C.DARK_GREEN + x + " " + z + C.DARK_AQUA + " " + file.getName()); + } catch (Throwable e) { + Iris.error("Failed to read Tectonic Plate " + file.getAbsolutePath() + " creating a new chunk instead."); + Iris.reportError(e); + if (!(e instanceof EOFException)) { + e.printStackTrace(); + } + Iris.panic(); + region = new TectonicPlate(worldHeight, x, z); + loadedRegions.put(k, region); + Iris.debug("Created new Tectonic Plate (Due to Load Failure) " + C.DARK_GREEN + x + " " + z); } - region = new TectonicPlate(worldHeight, x, z); - loadedRegions.put(k, region); - Iris.debug("Created new Tectonic Plate " + C.DARK_GREEN + x + " " + z); use(k); return region; - }).get(); - }); + } + + region = new TectonicPlate(worldHeight, x, z); + loadedRegions.put(k, region); + Iris.debug("Created new Tectonic Plate " + C.DARK_GREEN + x + " " + z); + use(k); + return region; + })); } private void use(Long key) { diff --git a/core/src/main/java/com/volmit/iris/util/parallel/StreamUtils.java b/core/src/main/java/com/volmit/iris/util/parallel/StreamUtils.java index 0c88d0d35..dad656936 100644 --- a/core/src/main/java/com/volmit/iris/util/parallel/StreamUtils.java +++ b/core/src/main/java/com/volmit/iris/util/parallel/StreamUtils.java @@ -29,6 +29,11 @@ public class StreamUtils { @SneakyThrows public static void forEach(Stream stream, Consumer task, @Nullable MultiBurst burst) { if (burst == null) stream.forEach(task); - else burst.submit(() -> stream.parallel().forEach(task)).get(); + else { + var list = stream.toList(); + var exec = burst.burst(list.size()); + list.forEach(val -> exec.queue(() -> task.accept(val))); + exec.complete(); + } } }