mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-25 18:09:17 +00:00
fix async tracker deadlock
This commit is contained in:
@@ -9,7 +9,7 @@ import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
public final class FixedThreadExecutor {
|
||||
private final Thread[] workers;
|
||||
private final MpmcQueue<Runnable> channel;
|
||||
public final MpmcQueue<Runnable> channel;
|
||||
private static volatile boolean SHUTDOWN = false;
|
||||
|
||||
public FixedThreadExecutor(int numThreads, int queue, String prefix) {
|
||||
@@ -72,12 +72,17 @@ public final class FixedThreadExecutor {
|
||||
private record Worker(MpmcQueue<Runnable> channel) implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while (!SHUTDOWN) {
|
||||
while (true) {
|
||||
final Runnable task = channel.recv();
|
||||
if (task != null) {
|
||||
task.run();
|
||||
} else if (!SHUTDOWN) {
|
||||
LockSupport.park();
|
||||
} else if (SHUTDOWN) {
|
||||
break;
|
||||
} else if (channel.isEmpty()) {
|
||||
Thread.yield();
|
||||
if (channel.isEmpty()) {
|
||||
LockSupport.park();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,10 @@ public final class AsyncTracker {
|
||||
}
|
||||
|
||||
public static void onTickEnd(MinecraftServer server) {
|
||||
if (!TRACKER_EXECUTOR.channel.isEmpty()) {
|
||||
// not likely
|
||||
TRACKER_EXECUTOR.unpack();
|
||||
}
|
||||
for (ServerLevel world : server.getAllLevels()) {
|
||||
Future<TrackerCtx>[] task = world.trackerTask;
|
||||
if (task != null) {
|
||||
|
||||
Reference in New Issue
Block a user