mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Locks
This commit is contained in:
parent
fc4377abaf
commit
d0fb3dde66
@ -186,18 +186,19 @@ public interface Matter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default <T> MatterSlice<T> slice(Class<?> c) {
|
default <T> MatterSlice<T> slice(Class<?> c) {
|
||||||
if (!hasSlice(c)) {
|
MatterSlice<T> slice = (MatterSlice<T>) getSlice(c);
|
||||||
MatterSlice<?> s = createSlice(c, this);
|
if (slice == null) {
|
||||||
|
slice = (MatterSlice<T>) createSlice(c, this);
|
||||||
|
|
||||||
if (s == null) {
|
if (slice == null) {
|
||||||
Iris.error("Unable to find a slice for class " + C.DARK_RED + c.getCanonicalName());
|
Iris.error("Unable to find a slice for class " + C.DARK_RED + c.getCanonicalName());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
putSlice(c, (MatterSlice<T>) s);
|
putSlice(c, slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (MatterSlice<T>) getSlice(c);
|
return slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -254,11 +255,15 @@ public interface Matter {
|
|||||||
*/
|
*/
|
||||||
Map<Class<?>, MatterSlice<?>> getSliceMap();
|
Map<Class<?>, MatterSlice<?>> getSliceMap();
|
||||||
|
|
||||||
|
|
||||||
default void write(File f) throws IOException {
|
default void write(File f) throws IOException {
|
||||||
FileOutputStream out = new FileOutputStream(f);
|
write(f, true);
|
||||||
GZIPOutputStream gzo = new GZIPOutputStream(out);
|
}
|
||||||
write(gzo);
|
|
||||||
gzo.close();
|
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 {
|
static Matter read(File f) throws IOException, ClassNotFoundException {
|
||||||
FileInputStream in = new FileInputStream(f);
|
FileInputStream in = new FileInputStream(f);
|
||||||
GZIPInputStream gzi = new GZIPInputStream(in);
|
Matter m = read(in);
|
||||||
Matter m = read(gzi);
|
in.close();
|
||||||
gzi.close();
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import java.util.function.Supplier;
|
|||||||
public class HyperLock {
|
public class HyperLock {
|
||||||
private final ConcurrentLinkedHashMap<Long, ReentrantLock> locks;
|
private final ConcurrentLinkedHashMap<Long, ReentrantLock> locks;
|
||||||
private final BiFunction<? super Long, ? super ReentrantLock, ? extends ReentrantLock> accessor;
|
private final BiFunction<? super Long, ? super ReentrantLock, ? extends ReentrantLock> accessor;
|
||||||
|
private boolean enabled = true;
|
||||||
|
|
||||||
public HyperLock() {
|
public HyperLock() {
|
||||||
this(1024, false);
|
this(1024, false);
|
||||||
@ -120,10 +121,24 @@ public class HyperLock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void lock(int x, int z) {
|
public void lock(int x, int z) {
|
||||||
|
if(!enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
getLock(x, z).lock();
|
getLock(x, z).lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unlock(int x, int z) {
|
public void unlock(int x, int z) {
|
||||||
|
if(!enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
getLock(x, z).unlock();
|
getLock(x, z).unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disable() {
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user