-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move SavedData.save to IO worker to avoid synchronous IO on main thre…
…ad by default
- Loading branch information
Showing
5 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
patches/net/minecraft/util/worldupdate/WorldUpgrader.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- a/net/minecraft/util/worldupdate/WorldUpgrader.java | ||
+++ b/net/minecraft/util/worldupdate/WorldUpgrader.java | ||
@@ -111,6 +_,7 @@ | ||
LOGGER.info("Upgrading blocks"); | ||
new WorldUpgrader.ChunkUpgrader().upgrade(); | ||
this.overworldDataStorage.save(); | ||
+ net.neoforged.neoforge.common.IOUtilities.waitUntilIOWorkerComplete(); | ||
i = Util.getMillis() - i; | ||
LOGGER.info("World optimizaton finished after {} seconds", i / 1000L); | ||
this.finished = true; |
9 changes: 7 additions & 2 deletions
9
patches/net/minecraft/world/level/saveddata/SavedData.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tests/src/junit/java/net/neoforged/neoforge/unittest/IOUtilitiesWorkerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.unittest; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import net.neoforged.neoforge.common.IOUtilities; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class IOUtilitiesWorkerTest { | ||
/** | ||
* Tests that waiting on the IO worker will complete remaining tasks | ||
*/ | ||
@Test | ||
void testWaitOnWorker() { | ||
AtomicBoolean value = new AtomicBoolean(false); | ||
IOUtilities.withIOWorker(() -> { | ||
try { | ||
Thread.sleep(2000); | ||
} catch (InterruptedException ignored) {} | ||
value.set(true); | ||
}); | ||
Assertions.assertFalse(value.get(), "Value should not be set yet"); | ||
IOUtilities.waitUntilIOWorkerComplete(); | ||
Assertions.assertTrue(value.get(), "Value should be set after waiting"); | ||
} | ||
} |