Skip to content

Commit

Permalink
properly fixed getChunk() deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
KaptainWutax committed Sep 22, 2020
1 parent 64124c6 commit 870c548
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 41 deletions.
6 changes: 5 additions & 1 deletion src/main/java/dimthread/DimThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public static void swapThreadsAndRun(Runnable task, Object... threadedObjects) {
}

public static void attach(Thread thread, ServerWorld world) {
thread.setName(MOD_ID + "_" + world.getRegistryKey().getValue().getPath());
attach(thread, world.getRegistryKey().getValue().getPath());
}

public static void attach(Thread thread, String name) {
thread.setName(MOD_ID + "_" + name);
}

public static boolean owns(Thread thread) {
Expand Down
37 changes: 0 additions & 37 deletions src/main/java/dimthread/mixin/EntityMixin.java

This file was deleted.

11 changes: 10 additions & 1 deletion src/main/java/dimthread/mixin/MinecraftServerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BooleanSupplier;

Expand Down Expand Up @@ -50,6 +51,7 @@ public Iterator<?> tickWorlds(Iterator<?> oldValue) {
target = "Ljava/lang/Iterable;iterator()Ljava/util/Iterator;"))
public void tickWorlds(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
AtomicReference<CrashReport> crashReport = new AtomicReference<>();
AtomicInteger completed = new AtomicInteger();

this.pool.iterate(this.getWorlds().iterator(), serverWorld -> {
DimThread.attach(Thread.currentThread(), serverWorld);
Expand All @@ -63,7 +65,14 @@ public void tickWorlds(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
}

try {
DimThread.swapThreadsAndRun(() -> serverWorld.tick(shouldKeepTicking), serverWorld, serverWorld.getChunkManager());
DimThread.swapThreadsAndRun(() -> {
serverWorld.tick(shouldKeepTicking);
completed.getAndIncrement();

while(completed.get() != 3) {
serverWorld.getChunkManager().executeQueuedTasks();
}
}, serverWorld, serverWorld.getChunkManager());
} catch(Throwable var6) {
crashReport.set(CrashReport.create(var6, "Exception ticking world"));
serverWorld.addDetailsToCrashReport(crashReport.get());
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/dimthread.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"MinecraftServerMixin",
"ServerChunkManagerMixin",
"RedstoneWireBlockMixin",
"WorldMixin",
"EntityMixin"
"WorldMixin"
],
"client": [
],
Expand Down

0 comments on commit 870c548

Please sign in to comment.