Always synchronise on target for regionized queue mergeInto

While for merging the synchronisation occured, it did not synchronise
for splitting. This resolves a possible CME that may occur while
splitting regions.
This commit is contained in:
Spottedleaf 2023-06-27 13:43:51 -07:00
parent 34039e3709
commit 81fe50f26f

View File

@ -4064,7 +4064,7 @@ index 0000000000000000000000000000000000000000..8e31c6ee9ee16aff699e124a9b0554ea
+}
diff --git a/src/main/java/io/papermc/paper/threadedregions/RegionizedTaskQueue.java b/src/main/java/io/papermc/paper/threadedregions/RegionizedTaskQueue.java
new file mode 100644
index 0000000000000000000000000000000000000000..2e4514e5a45db6e625ef7799b63a9285a3bc1030
index 0000000000000000000000000000000000000000..98ddb674b63a4777a98152ea960debf48aa2bc35
--- /dev/null
+++ b/src/main/java/io/papermc/paper/threadedregions/RegionizedTaskQueue.java
@@ -0,0 +1,768 @@
@ -4382,13 +4382,12 @@ index 0000000000000000000000000000000000000000..2e4514e5a45db6e625ef7799b63a9285
+ public void mergeInto(final PrioritisedQueue target) {
+ synchronized (this) {
+ this.isDestroyed = true;
+ synchronized (target) {
+ mergeInto(target, this.queues);
+ }
+ }
+ }
+
+ private static void mergeInto(final PrioritisedQueue target, final ArrayDeque<ChunkBasedPriorityTask>[] thisQueues) {
+ synchronized (target) {
+ final ArrayDeque<ChunkBasedPriorityTask>[] otherQueues = target.queues;
+ for (int i = 0; i < thisQueues.length; ++i) {
+ final ArrayDeque<ChunkBasedPriorityTask> fromQ = thisQueues[i];
@ -4405,6 +4404,7 @@ index 0000000000000000000000000000000000000000..2e4514e5a45db6e625ef7799b63a9285
+ }
+ }
+ }
+ }
+
+ // into is a map of section coordinate to region
+ public void split(final boolean isChunkData,