mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-25 03:55:35 +01:00
synchronize on block map access
This commit is contained in:
parent
116a1869b1
commit
6408320843
@ -43,13 +43,17 @@ public class DefaultFaweQueueMap implements IFaweQueueMap {
|
||||
|
||||
@Override
|
||||
public Collection<FaweChunk> getFaweCunks() {
|
||||
return new HashSet<>(blocks.values());
|
||||
synchronized (blocks) {
|
||||
return new HashSet<>(blocks.values());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachChunk(RunnableVal<FaweChunk> onEach) {
|
||||
for (Map.Entry<Long, FaweChunk> entry : blocks.entrySet()) {
|
||||
onEach.run(entry.getValue());
|
||||
synchronized (blocks) {
|
||||
for (Map.Entry<Long, FaweChunk> entry : blocks.entrySet()) {
|
||||
onEach.run(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,31 +47,35 @@ public class WeakFaweQueueMap implements IFaweQueueMap {
|
||||
@Override
|
||||
public Collection<FaweChunk> getFaweCunks() {
|
||||
HashSet<FaweChunk> set = new HashSet<>();
|
||||
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
|
||||
FaweChunk value = entry.getValue().get();
|
||||
if (value != null) {
|
||||
set.add(value);
|
||||
} else {
|
||||
Fawe.debug("Skipped modifying chunk due to low memory (1)");
|
||||
iter.remove();
|
||||
synchronized (blocks) {
|
||||
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
|
||||
FaweChunk value = entry.getValue().get();
|
||||
if (value != null) {
|
||||
set.add(value);
|
||||
} else {
|
||||
Fawe.debug("Skipped modifying chunk due to low memory (1)");
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachChunk(RunnableVal<FaweChunk> onEach) {
|
||||
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
|
||||
FaweChunk value = entry.getValue().get();
|
||||
if (value != null) {
|
||||
onEach.run(value);
|
||||
} else {
|
||||
Fawe.debug("Skipped modifying chunk due to low memory (2)");
|
||||
iter.remove();
|
||||
synchronized (blocks) {
|
||||
Iterator<Map.Entry<Long, Reference<FaweChunk>>> iter = blocks.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<Long, Reference<FaweChunk>> entry = iter.next();
|
||||
FaweChunk value = entry.getValue().get();
|
||||
if (value != null) {
|
||||
onEach.run(value);
|
||||
} else {
|
||||
Fawe.debug("Skipped modifying chunk due to low memory (2)");
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user