Paper/patches/server/0421-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch
Jason bc127ea819
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#6222)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
eec4aab0 SPIGOT-6657: Add getPlayer to SheepDyeWoolEvent
205213c6 SPIGOT-6656: CauldronLevelChangeEvent is not fired correctly when dripstone fills the cauldron

CraftBukkit Changes:
b8c522d5 SPIGOT-6657: Add getPlayer to SheepDyeWoolEvent
f04a77dc SPIGOT-6656: CauldronLevelChangeEvent is not fired correctly when dripstone fills the cauldron
d1dbcebc SPIGOT-6653: Canceling snow bucket placement removes snow from bucket
4f34a67b #891: Fix scheduler task ID overflow and duplication issues

Spigot Changes:
d03d7f12 BUILDTOOLS-604: Rebuild patches
2021-07-18 09:41:53 +02:00

52 lines
2.3 KiB
Diff

From 0000000000000000000000000000000000000000 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
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 2b4c35d9bd186fd7c3650a7ad791cd67fb64e635..e7c78106aa34d948a77cf72d5716e17d10beae72 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -178,17 +178,29 @@ 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) {
+ while ((task = queue.poll()) != null) { // Paper
task.run();
}
}