aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0017-Make-CallbackExecutor-strict-again.patch
blob: e37cf530bbe5a277e4d0f30f93f309d0219b8c93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
index ea27e6b1340a42c675bc68ed75f100569114be7a..4da0cbe58dad0f66e0d056c71684120514dcac6a 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -157,17 +157,28 @@ 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<>();
+        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) {
+                LOGGER.error("Failed to schedule runnable", new IllegalStateException("Already queued"));
+                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();
             }
         }