Skip to content

Commit

Permalink
Make loadChunksAsync callback thread-safe
Browse files Browse the repository at this point in the history
Need to perform synchronisation on the return list to avoid CMEs
  • Loading branch information
Spottedleaf committed Jul 25, 2023
1 parent 57983f7 commit b2d7bdb
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <[email protected]>
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) {

0 comments on commit b2d7bdb

Please sign in to comment.