mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-05 15:26:28 +00:00
Only compute if absent/present if compute is not needed (locking opts)
This commit is contained in:
@@ -32,8 +32,8 @@ import java.util.function.Supplier;
|
||||
|
||||
public class HyperLock {
|
||||
private final ConcurrentLinkedHashMap<Long, ReentrantLock> locks;
|
||||
private final BiFunction<? super Long, ? super ReentrantLock, ? extends ReentrantLock> accessor;
|
||||
private boolean enabled = true;
|
||||
private boolean fair = false;
|
||||
|
||||
public HyperLock() {
|
||||
this(1024, false);
|
||||
@@ -44,6 +44,7 @@ public class HyperLock {
|
||||
}
|
||||
|
||||
public HyperLock(int capacity, boolean fair) {
|
||||
this.fair = fair;
|
||||
locks = new ConcurrentLinkedHashMap.Builder<Long, ReentrantLock>()
|
||||
.initialCapacity(capacity)
|
||||
.maximumWeightedCapacity(capacity)
|
||||
@@ -54,7 +55,6 @@ public class HyperLock {
|
||||
})
|
||||
.concurrencyLevel(32)
|
||||
.build();
|
||||
accessor = (k, v) -> v == null ? new ReentrantLock(fair) : v;
|
||||
}
|
||||
|
||||
public void with(int x, int z, Runnable r) {
|
||||
@@ -123,7 +123,7 @@ public class HyperLock {
|
||||
}
|
||||
|
||||
private ReentrantLock getLock(int x, int z) {
|
||||
return locks.compute(Cache.key(x, z), accessor);
|
||||
return locks.computeIfAbsent(Cache.key(x, z), k -> new ReentrantLock(fair));
|
||||
}
|
||||
|
||||
public void lock(int x, int z) {
|
||||
|
||||
Reference in New Issue
Block a user