Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/Spigot-Server-Patches/0491-Allow-multiple-callbacks-to-schedule-for-Callback-Ex.patch
Aikar aa241d2b64
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
2020-04-21 03:55:31 -04:00

53 Zeilen
2.0 KiB
Diff

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