lock when editing the chunks cache in SingletThreadQueueExtent

- Long2ObjectLinkedOpenHashMap is not thread-safe and should not be used from multiple threads at once
 - Fixes #851
This commit is contained in:
dordsor21 2021-01-14 15:42:38 +00:00
parent 3034419918
commit fa69c79160
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -114,7 +114,9 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen
for (IChunk chunk : this.chunks.values()) { for (IChunk chunk : this.chunks.values()) {
chunk.recycle(); chunk.recycle();
} }
getChunkLock.lock();
this.chunks.clear(); this.chunks.clear();
getChunkLock.unlock();
} }
this.enabledQueue = true; this.enabledQueue = true;
this.lastChunk = null; this.lastChunk = null;
@ -163,7 +165,9 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen
lastChunk = null; lastChunk = null;
} }
final long index = MathMan.pairInt(chunk.getX(), chunk.getZ()); final long index = MathMan.pairInt(chunk.getX(), chunk.getZ());
getChunkLock.lock();
chunks.remove(index, chunk); chunks.remove(index, chunk);
getChunkLock.unlock();
V future = submitUnchecked(chunk); V future = submitUnchecked(chunk);
submissions.add(future); submissions.add(future);
return future; return future;
@ -374,7 +378,9 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen
} }
} }
} }
getChunkLock.lock();
chunks.clear(); chunks.clear();
getChunkLock.unlock();
} }
pollSubmissions(0, true); pollSubmissions(0, true);
} }