From d0fb3dde66545bec7abe7b813bebf57125c5aca5 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 06:06:39 -0400 Subject: [PATCH] Locks --- .../com/volmit/iris/util/matter/Matter.java | 28 +++++++++++-------- .../volmit/iris/util/parallel/HyperLock.java | 15 ++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/matter/Matter.java b/src/main/java/com/volmit/iris/util/matter/Matter.java index d81cbe08a..e80fa288d 100644 --- a/src/main/java/com/volmit/iris/util/matter/Matter.java +++ b/src/main/java/com/volmit/iris/util/matter/Matter.java @@ -186,18 +186,19 @@ public interface Matter { } default MatterSlice slice(Class c) { - if (!hasSlice(c)) { - MatterSlice s = createSlice(c, this); + MatterSlice slice = (MatterSlice) getSlice(c); + if (slice == null) { + slice = (MatterSlice) createSlice(c, this); - if (s == null) { + if (slice == null) { Iris.error("Unable to find a slice for class " + C.DARK_RED + c.getCanonicalName()); return null; } - putSlice(c, (MatterSlice) s); + putSlice(c, slice); } - return (MatterSlice) getSlice(c); + return slice; } /** @@ -254,11 +255,15 @@ public interface Matter { */ Map, MatterSlice> getSliceMap(); + default void write(File f) throws IOException { - FileOutputStream out = new FileOutputStream(f); - GZIPOutputStream gzo = new GZIPOutputStream(out); - write(gzo); - gzo.close(); + write(f, true); + } + + default void write(File f, boolean compression) throws IOException { + OutputStream out = new FileOutputStream(f); + write(out); + out.close(); } /** @@ -310,9 +315,8 @@ public interface Matter { static Matter read(File f) throws IOException, ClassNotFoundException { FileInputStream in = new FileInputStream(f); - GZIPInputStream gzi = new GZIPInputStream(in); - Matter m = read(gzi); - gzi.close(); + Matter m = read(in); + in.close(); return m; } 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 f93358a29..660bb9c9f 100644 --- a/src/main/java/com/volmit/iris/util/parallel/HyperLock.java +++ b/src/main/java/com/volmit/iris/util/parallel/HyperLock.java @@ -33,6 +33,7 @@ import java.util.function.Supplier; public class HyperLock { private final ConcurrentLinkedHashMap locks; private final BiFunction accessor; + private boolean enabled = true; public HyperLock() { this(1024, false); @@ -120,10 +121,24 @@ public class HyperLock { } public void lock(int x, int z) { + if(!enabled) + { + return; + } + getLock(x, z).lock(); } public void unlock(int x, int z) { + if(!enabled) + { + return; + } + getLock(x, z).unlock(); } + + public void disable() { + enabled = false; + } }