mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Test paper deadlock fix
This commit is contained in:
parent
2fde7b7879
commit
3be4b08bb0
@ -4,18 +4,21 @@ import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||
import com.volmit.iris.scaffold.cache.Cache;
|
||||
import com.volmit.iris.scaffold.stream.BasicStream;
|
||||
import com.volmit.iris.scaffold.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.ChronoLatch;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
// TODO BETTER CACHE SOLUTION
|
||||
public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStream<T>
|
||||
{
|
||||
private final ProceduralStream<T> stream;
|
||||
private final ConcurrentLinkedHashMap<Long, T> cache;
|
||||
private ChronoLatch cl = new ChronoLatch(1000);
|
||||
private final Semaphore locker;
|
||||
|
||||
public CachedStream2D(ProceduralStream<T> stream, int size)
|
||||
{
|
||||
super();
|
||||
this.stream = stream;
|
||||
locker = new Semaphore(30);
|
||||
cache = new ConcurrentLinkedHashMap.Builder<Long, T>()
|
||||
.initialCapacity(size)
|
||||
.maximumWeightedCapacity(size)
|
||||
@ -38,8 +41,15 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
|
||||
@Override
|
||||
public T get(double x, double z)
|
||||
{
|
||||
try {
|
||||
locker.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long ck = Cache.key((int) x, (int) z);
|
||||
return cache.compute(ck, (k, v) -> v != null ? v : stream.get(Cache.keyX(ck), Cache.keyZ(ck)));
|
||||
T f = cache.compute(ck, (k, v) -> v != null ? v : stream.get(Cache.keyX(ck), Cache.keyZ(ck)));
|
||||
locker.release();
|
||||
return f;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user