2021-06-11 14:02:28 +02:00
|
|
|
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
|
2021-06-16 02:50:38 +02:00
|
|
|
index b64a3dd03a22542b070eae34f0eaa9b321dca4ec..218a20e85c9b6d31bcdf5432f4ea9cf0c0d7b952 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
2021-06-15 15:20:52 +02:00
|
|
|
@@ -173,17 +173,29 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
2021-06-11 14:02:28 +02:00
|
|
|
public final CallbackExecutor callbackExecutor = new CallbackExecutor();
|
|
|
|
public static final class CallbackExecutor implements java.util.concurrent.Executor, Runnable {
|
|
|
|
|
2021-06-14 03:06:38 +02:00
|
|
|
- private final java.util.Queue<Runnable> queue = new java.util.ArrayDeque<>();
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // 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
|
2021-06-14 03:06:38 +02:00
|
|
|
+ private java.util.Queue<Runnable> queue = new java.util.ArrayDeque<>(); // Paper - remove final
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute(Runnable runnable) {
|
2021-06-14 03:06:38 +02:00
|
|
|
+ if (this.queue == null) {
|
|
|
|
+ this.queue = new java.util.ArrayDeque<>();
|
|
|
|
+ }
|
|
|
|
this.queue.add(runnable);
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2021-06-14 03:06:38 +02:00
|
|
|
+ if (this.queue == null) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return;
|
|
|
|
+ }
|
2021-06-14 03:06:38 +02:00
|
|
|
+ java.util.Queue<Runnable> queue = this.queue;
|
|
|
|
+ this.queue = null;
|
|
|
|
+ // Paper end
|
|
|
|
Runnable task;
|
2021-06-14 05:06:11 +02:00
|
|
|
- while ((task = this.queue.poll()) != null) {
|
|
|
|
+ while ((task = queue.poll()) != null) { // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
task.run();
|
2021-06-14 05:06:11 +02:00
|
|
|
}
|
|
|
|
}
|