2021-08-26 04:16:27 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
|
|
|
Date: Fri, 24 Apr 2020 09:06:15 -0700
|
|
|
|
Subject: [PATCH] Make CallbackExecutor strict again
|
|
|
|
|
|
|
|
The correct fix for double scheduling is to avoid it. The reason
|
|
|
|
this class is used is because double scheduling causes issues
|
|
|
|
elsewhere, and it acts as an explicit detector of what double
|
|
|
|
schedules. Effectively, use the callback executor as a tool of
|
|
|
|
finding issues rather than hiding these issues.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
2022-03-02 10:44:22 +01:00
|
|
|
index 4f7894d9458733a5bf42e6d1094db2aaf5ae8ea0..7595f2bd6b26946e9f437dbd962a3b23e95a52b6 100644
|
2021-08-26 04:16:27 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
2022-03-01 06:43:03 +01:00
|
|
|
@@ -164,17 +164,28 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
2021-08-26 04:16:27 +02:00
|
|
|
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<>();
|
|
|
|
+ private Runnable queued; // Paper - revert CB changes
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute(Runnable runnable) {
|
|
|
|
- this.queue.add(runnable);
|
|
|
|
+ // Paper start - revert CB changes
|
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp("Callback Executor execute");
|
|
|
|
+ if (this.queued != null) {
|
2022-02-28 22:43:31 +01:00
|
|
|
+ LOGGER.error("Failed to schedule runnable", new IllegalStateException("Already queued"));
|
2021-08-26 04:16:27 +02:00
|
|
|
+ throw new IllegalStateException("Already queued");
|
|
|
|
+ }
|
|
|
|
+ this.queued = runnable;
|
|
|
|
+ // Paper end - revert CB changes
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
- Runnable task;
|
|
|
|
- while ((task = this.queue.poll()) != null) {
|
|
|
|
+ // Paper start - revert CB changes
|
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp("Callback Executor execute");
|
|
|
|
+ Runnable task = this.queued;
|
|
|
|
+ if (task != null) {
|
|
|
|
+ this.queued = null;
|
|
|
|
+ // Paper end - revert CB changes
|
|
|
|
task.run();
|
|
|
|
}
|
|
|
|
}
|