Allow multiple callbacks to schedule for Callback Executor
ChunkMapDistance polls multiple entries for pendingChunkUpdates Each of these have the potential to move a chunk in and out of "Loaded" state, which will result in multiple callbacks being needed within a single tick of ChunkMapDistance Use an ArrayDeque to store this Queue
This commit is contained in:
parent
a2064a4135
commit
aa241d2b64
|
@ -0,0 +1,52 @@
|
|||
From 429c6c3f9e55451e7f2e0065879884f3e0e13217 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Tue, 21 Apr 2020 03:51:53 -0400
|
||||
Subject: [PATCH] Allow multiple callbacks to schedule for Callback Executor
|
||||
|
||||
ChunkMapDistance polls multiple entries for pendingChunkUpdates
|
||||
|
||||
Each of these have the potential to move a chunk in and out of
|
||||
"Loaded" state, which will result in multiple callbacks being
|
||||
needed within a single tick of ChunkMapDistance
|
||||
|
||||
Use an ArrayDeque to store this Queue
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
index 8b2eed1051..ee0cabadc8 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
@@ -87,25 +87,22 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
|
||||
public final CallbackExecutor callbackExecutor = new CallbackExecutor();
|
||||
public static final class CallbackExecutor implements java.util.concurrent.Executor, Runnable {
|
||||
|
||||
- private Runnable queued;
|
||||
+ // Paper start - replace impl with Deque - possible multiple is needed in single pass
|
||||
+ private java.util.Deque<Runnable> queued = new java.util.ArrayDeque<>();
|
||||
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
- if (queued != null) {
|
||||
- MinecraftServer.LOGGER.fatal("Failed to schedule runnable", new IllegalStateException("Already queued")); // Paper - make sure this is printed
|
||||
- throw new IllegalStateException("Already queued");
|
||||
- }
|
||||
- queued = runnable;
|
||||
+ queued.add(runnable); // Paper
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
- Runnable task = queued;
|
||||
- queued = null;
|
||||
- if (task != null) {
|
||||
+ Runnable task;
|
||||
+ while ((task = queued.pollFirst()) != null) {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
+ // Paper end
|
||||
};
|
||||
// CraftBukkit end
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
Loading…
Reference in New Issue