mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Locking & Thread fixes
This commit is contained in:
parent
600995a220
commit
f258d5f932
@ -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> T withResult(int x, int z, Supplier<T> r) {
|
||||
|
@ -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 <T> CompletableFuture<T> completeValue(Supplier<T> o) {
|
||||
return CompletableFuture.supplyAsync(o, getService());
|
||||
}
|
||||
|
||||
public void shutdownNow() {
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
heartbeat.interrupt();
|
||||
|
Loading…
x
Reference in New Issue
Block a user