Skip to content

Commit

Permalink
Set queuedUnload correctly when unloading via GC
Browse files Browse the repository at this point in the history
Signed-off-by: Ross Allan <rallanpcl@gmail.com>
  • Loading branch information
LunNova committed May 6, 2013
1 parent 528d93b commit 7c07aa6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/common/me/nallar/patched/storage/ThreadedChunkProvider.java
Expand Up @@ -154,7 +154,7 @@ public void tick() {
chunkCoordIntPair.chunkXPos = x;
chunkCoordIntPair.chunkZPos = z;
Chunk chunk = (Chunk) chunks.getValueByKey(key);
if (chunk == null || chunk.partiallyUnloaded) {
if (chunk == null || chunk.partiallyUnloaded || !chunk.queuedUnload) {
continue;
}
if (persistentChunks.containsKey(chunkCoordIntPair) || unloadingChunks.containsItem(key) || playerManager.getOrCreateChunkWatcher(x, z, false) != null || !fireBukkitUnloadEvent(chunk)) {
Expand Down Expand Up @@ -322,6 +322,17 @@ public boolean unloadChunk(int x, int z) {
return unloadStage0.add(hash);
}

@Override
@Declare
public void unloadChunkForce(long hash) {
if (unloadStage0.add(hash)) {
Chunk chunk = (Chunk) chunks.getValueByKey(hash);
if (chunk != null) {
chunk.queuedUnload = true;
}
}
}

@Override
public void unloadChunksIfNotNearSpawn(int x, int z) {
unloadChunk(x, z);
Expand Down Expand Up @@ -386,7 +397,9 @@ public final Chunk provideChunk(int x, int z) {

@Override
public final Chunk loadChunk(int x, int z) {
return getChunkAt(x, z, true, false, null);
Chunk chunk = getChunkAt(x, z, true, false, null);
chunk.queuedUnload = false;
return chunk;
}

@Override
Expand Down
Expand Up @@ -44,10 +44,10 @@ public static void garbageCollect(WorldServer worldServer) {
chunksToUnload.remove(ChunkCoordIntPair.chunkXZ2Int(chunkCoordIntPair.chunkXPos, chunkCoordIntPair.chunkZPos));
}

Set<Long> chunksToUnload_ = chunkProvider.getChunksToUnloadSet();
synchronized (chunksToUnload_) {
chunksToUnload_.addAll(chunksToUnload);
for (long chunk : chunksToUnload) {
chunkProvider.unloadChunkForce(chunk);
}

profiler.endSection();
}
}

0 comments on commit 7c07aa6

Please sign in to comment.