synchronize on block map access

This commit is contained in:
Jesse Boyd 2017-01-30 06:26:47 +11:00
parent 116a1869b1
commit 6408320843
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 30 additions and 22 deletions

View File

@ -43,15 +43,19 @@ public class DefaultFaweQueueMap implements IFaweQueueMap {
@Override
public Collection<FaweChunk> getFaweCunks() {
synchronized (blocks) {
return new HashSet<>(blocks.values());
}
}
@Override
public void forEachChunk(RunnableVal<FaweChunk> onEach) {
synchronized (blocks) {
for (Map.Entry<Long, FaweChunk> entry : blocks.entrySet()) {
onEach.run(entry.getValue());
}
}
}
@Override
public FaweChunk getFaweChunk(int cx, int cz) {

View File

@ -47,6 +47,7 @@ public class WeakFaweQueueMap implements IFaweQueueMap {
@Override
public Collection<FaweChunk> getFaweCunks() {
HashSet<FaweChunk> set = new HashSet<>();
synchronized (blocks) {
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
@ -60,9 +61,11 @@ public class WeakFaweQueueMap implements IFaweQueueMap {
}
return set;
}
}
@Override
public void forEachChunk(RunnableVal<FaweChunk> onEach) {
synchronized (blocks) {
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
@ -75,6 +78,7 @@ public class WeakFaweQueueMap implements IFaweQueueMap {
}
}
}
}
@Override
public FaweChunk getFaweChunk(int cx, int cz) {