Locking & Thread fixes

This commit is contained in:
Daniel Mills 2021-08-07 08:15:09 -04:00
parent 600995a220
commit f258d5f932
2 changed files with 45 additions and 6 deletions

View File

@ -64,14 +64,48 @@ public class HyperLock {
public void withNasty(int x, int z, NastyRunnable r) throws Throwable { public void withNasty(int x, int z, NastyRunnable r) throws Throwable {
lock(x, z); lock(x, z);
r.run(); Throwable ee = null;
unlock(x, z); 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 { public void withIO(int x, int z, IORunnable r) throws IOException {
lock(x, z); lock(x, z);
r.run(); IOException ee = null;
unlock(x, z); try {
r.run();
}
catch(IOException e)
{
ee = e;
}
finally
{
unlock(x, z);
if(ee != null)
{
throw ee;
}
}
} }
public <T> T withResult(int x, int z, Supplier<T> r) { public <T> T withResult(int x, int z, Supplier<T> r) {

View File

@ -27,6 +27,7 @@ import com.volmit.iris.util.scheduling.Looper;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
public class MultiBurst { public class MultiBurst {
public static final MultiBurst burst = new MultiBurst("Iris", IrisSettings.get().getConcurrency().getMiscThreadPriority(), IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getMiscThreadCount())); 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) { if (M.ms() - last.get() > TimeUnit.MINUTES.toMillis(1) && service != null) {
service.shutdown(); service.shutdown();
service = null; service = null;
Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resource."); Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resources.");
} }
return 60000; return 60000;
} }
}; };
heartbeat.setName(name); heartbeat.setName(name + " Monitor");
heartbeat.start(); heartbeat.start();
} }
@ -123,6 +124,10 @@ public class MultiBurst {
return CompletableFuture.runAsync(o, getService()); return CompletableFuture.runAsync(o, getService());
} }
public <T> CompletableFuture<T> completeValue(Supplier<T> o) {
return CompletableFuture.supplyAsync(o, getService());
}
public void shutdownNow() { public void shutdownNow() {
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + "."); Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
heartbeat.interrupt(); heartbeat.interrupt();