mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +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 {
|
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) {
|
||||||
|
@ -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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user