diff options
Diffstat (limited to 'patches/server/0411-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch')
-rw-r--r-- | patches/server/0411-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/patches/server/0411-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch b/patches/server/0411-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch new file mode 100644 index 0000000000..1ad36331ec --- /dev/null +++ b/patches/server/0411-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar <[email protected]> +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 + +We make sure to also implement a pattern that is recursion safe too. + +diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java +index 2cb807f7095648948527b5b9151770193970cc00..7fa35cba408d036e649e6d63bace88e6047c02b4 100644 +--- a/src/main/java/net/minecraft/server/level/ChunkMap.java ++++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +@@ -172,15 +172,27 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider + public final CallbackExecutor callbackExecutor = new CallbackExecutor(); + public static final class CallbackExecutor implements java.util.concurrent.Executor, Runnable { + +- private final java.util.Queue<Runnable> queue = new java.util.ArrayDeque<>(); ++ // Paper start - replace impl with recursive safe multi entry queue ++ // it's possible to schedule multiple tasks currently, so it's vital we change this impl ++ // If we recurse into the executor again, we will append to another queue, ensuring task order consistency ++ private java.util.Queue<Runnable> queue = new java.util.ArrayDeque<>(); // Paper - remove final + + @Override + public void execute(Runnable runnable) { ++ if (this.queue == null) { ++ this.queue = new java.util.ArrayDeque<>(); ++ } + this.queue.add(runnable); + } + + @Override + public void run() { ++ if (this.queue == null) { ++ return; ++ } ++ java.util.Queue<Runnable> queue = this.queue; ++ this.queue = null; ++ // Paper end + Runnable task; + while ((task = this.queue.poll()) != null) { + task.run(); |