Do not schedule to main for getChunkImmediately type calls (#2362)

They are MT-Safe already. These changes reduce deadlock chances
given these calls are used in Entity#isValid(), and plugins
check this in packet handling...
This commit is contained in:
Spottedleaf 2019-07-25 18:36:26 -07:00
parent 405dd2640c
commit e170ab7fce
4 changed files with 8 additions and 44 deletions

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Actually-Limit-Natural-Spawns-To-Limit
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 744fa825e6..3b7288c6cb 100644
index a58cfc14bb..26216fe72c 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {

View file

@ -8,7 +8,7 @@ This patch also adds a chunk status cache on region files (note that
its only purpose is to cache the status on DISK)
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 220cd197fa..775b5f7fe3 100644
index 9765eaf24c..d714b8d01b 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {
@ -27,24 +27,9 @@ index 220cd197fa..775b5f7fe3 100644
+
+ @Nullable
+ public IChunkAccess getChunkAtImmediately(int x, int z) {
+ if (Thread.currentThread() != this.serverThread) {
+ return CompletableFuture.supplyAsync(() -> {
+ return this.getChunkAtImmediately(x, z);
+ }, this.serverThreadQueue).join();
+ }
+
+ long k = ChunkCoordIntPair.pair(x, z);
+
+ IChunkAccess ichunkaccess;
+
+ for (int l = 0; l < 4; ++l) {
+ if (k == this.cachePos[l]) {
+ ichunkaccess = this.cacheChunk[l];
+ if (ichunkaccess != null) { // CraftBukkit - the chunk can become accessible in the meantime TODO for non-null chunks it might also make sense to check that the chunk's state hasn't changed in the meantime
+ return ichunkaccess;
+ }
+ }
+ }
+ // Note: Bypass cache to make this MT-Safe
+
+ PlayerChunk playerChunk = this.getChunk(k);
+ if (playerChunk == null) {

View file

@ -167,7 +167,7 @@ index 857b2f8868..bbf136614c 100644
}
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 36a89817f8..dd6e69a0f1 100644
index 36a89817f8..baf3bd461b 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {
@ -178,24 +178,9 @@ index 36a89817f8..dd6e69a0f1 100644
+ // Note: Partially copied from the getChunkAt method below
+ @Nullable
+ public Chunk getChunkAtIfCachedImmediately(int x, int z) {
+ if (Thread.currentThread() != this.serverThread) {
+ return CompletableFuture.supplyAsync(() -> {
+ return this.getChunkAtIfCachedImmediately(x, z);
+ }, this.serverThreadQueue).join();
+ }
+
+ long k = ChunkCoordIntPair.pair(x, z);
+
+ IChunkAccess ichunkaccess;
+
+ for (int l = 0; l < 4; ++l) {
+ if (k == this.cachePos[l] && ChunkStatus.FULL == this.cacheStatus[l]) {
+ ichunkaccess = this.cacheChunk[l];
+ if (ichunkaccess instanceof Chunk) { // CraftBukkit - the chunk can become accessible in the meantime TODO for non-null chunks it might also make sense to check that the chunk's state hasn't changed in the meantime
+ return (Chunk)ichunkaccess;
+ }
+ }
+ }
+ // Note: Bypass cache to make this MT-Safe
+
+ PlayerChunk playerChunk = this.getChunk(k);
+ if (playerChunk == null) {
@ -207,15 +192,9 @@ index 36a89817f8..dd6e69a0f1 100644
+
+ @Nullable
+ public Chunk getChunkAtIfLoadedImmediately(int x, int z) {
+ if (Thread.currentThread() != this.serverThread) {
+ return CompletableFuture.supplyAsync(() -> {
+ return this.getChunkAtIfLoadedImmediately(x, z);
+ }, this.serverThreadQueue).join();
+ }
+
+ long k = ChunkCoordIntPair.pair(x, z);
+
+ // Note: Bypass cache since we need to check ticket level
+ // Note: Bypass cache since we need to check ticket level, and to make this MT-Safe
+
+ PlayerChunk playerChunk = this.getChunk(k);
+ if (playerChunk == null) {
@ -326,7 +305,7 @@ index 613d534aeb..f31a996aa5 100644
// CraftBukkit start - fire event
setGoalTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true);
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 35a67665a2..5c863860ae 100644
index 9c3e95bbbc..dcbc4ea7e1 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {

View file

@ -358,7 +358,7 @@ index 3ed48be382..c4d989f702 100644
}
}
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index dd6e69a0f1..978a9f9172 100644
index baf3bd461b..f351d021dc 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {