Make loadChunksAsync callback thread-safe

Need to perform synchronisation on the return list to avoid CMEs
This commit is contained in:
Spottedleaf 2023-07-25 12:00:33 -07:00
parent 57983f77f7
commit b2d7bdb0bb

View File

@ -0,0 +1,21 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 25 Jul 2023 11:47:18 -0700
Subject: [PATCH] Make loadChunksAsync callback thread-safe
Need to perform synchronisation on the return list to avoid CMEs
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 60b409e873d8f5d7975cce6e86ee2ed5525d348c..cf8f93734121e5c1959959f0ba13ee4e6db31959 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -347,7 +347,9 @@ public class ServerLevel extends Level implements WorldGenLevel {
java.util.function.Consumer<net.minecraft.world.level.chunk.ChunkAccess> consumer = (net.minecraft.world.level.chunk.ChunkAccess chunk) -> {
if (chunk != null) {
+ synchronized (ret) { // Folia - region threading - make callback thread-safe TODO rebase
ret.add(chunk);
+ } // Folia - region threading - make callback thread-safe TODO rebase
chunkProvider.addTicketAtLevel(TicketType.FUTURE_AWAIT, chunk.getPos(), ticketLevel, holderIdentifier);
}
if (loadedChunks.incrementAndGet() == requiredChunks) {