mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-04 10:11:29 +01:00
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:
parent
405dd2640c
commit
e170ab7fce
4 changed files with 8 additions and 44 deletions
|
@ -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
|
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
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
||||||
+++ b/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 {
|
@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {
|
||||||
|
|
|
@ -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)
|
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
|
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
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
||||||
+++ b/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 {
|
@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {
|
||||||
|
@ -27,24 +27,9 @@ index 220cd197fa..775b5f7fe3 100644
|
||||||
+
|
+
|
||||||
+ @Nullable
|
+ @Nullable
|
||||||
+ public IChunkAccess getChunkAtImmediately(int x, int z) {
|
+ 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);
|
+ long k = ChunkCoordIntPair.pair(x, z);
|
||||||
+
|
+
|
||||||
+ IChunkAccess ichunkaccess;
|
+ // Note: Bypass cache to make this MT-Safe
|
||||||
+
|
|
||||||
+ 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;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+
|
+
|
||||||
+ PlayerChunk playerChunk = this.getChunk(k);
|
+ PlayerChunk playerChunk = this.getChunk(k);
|
||||||
+ if (playerChunk == null) {
|
+ if (playerChunk == null) {
|
||||||
|
|
|
@ -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
|
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
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
||||||
+++ b/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 {
|
@@ -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
|
+ // Note: Partially copied from the getChunkAt method below
|
||||||
+ @Nullable
|
+ @Nullable
|
||||||
+ public Chunk getChunkAtIfCachedImmediately(int x, int z) {
|
+ 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);
|
+ long k = ChunkCoordIntPair.pair(x, z);
|
||||||
+
|
+
|
||||||
+ IChunkAccess ichunkaccess;
|
+ // Note: Bypass cache to make this MT-Safe
|
||||||
+
|
|
||||||
+ 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;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+
|
+
|
||||||
+ PlayerChunk playerChunk = this.getChunk(k);
|
+ PlayerChunk playerChunk = this.getChunk(k);
|
||||||
+ if (playerChunk == null) {
|
+ if (playerChunk == null) {
|
||||||
|
@ -207,15 +192,9 @@ index 36a89817f8..dd6e69a0f1 100644
|
||||||
+
|
+
|
||||||
+ @Nullable
|
+ @Nullable
|
||||||
+ public Chunk getChunkAtIfLoadedImmediately(int x, int z) {
|
+ 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);
|
+ 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);
|
+ PlayerChunk playerChunk = this.getChunk(k);
|
||||||
+ if (playerChunk == null) {
|
+ if (playerChunk == null) {
|
||||||
|
@ -326,7 +305,7 @@ index 613d534aeb..f31a996aa5 100644
|
||||||
// CraftBukkit start - fire event
|
// CraftBukkit start - fire event
|
||||||
setGoalTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
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
|
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
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
||||||
+++ b/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 {
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
||||||
|
|
|
@ -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
|
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
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
||||||
+++ b/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 {
|
@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {
|
||||||
|
|
Loading…
Reference in a new issue