From cc473be3327934258b345b1a6a95fd8d1333a71c Mon Sep 17 00:00:00 2001 From: cpw Date: Sun, 6 Sep 2020 17:55:03 -0400 Subject: [PATCH] Park the polling thread for a bit, if we're not the one driving the task list forwards. This allows for the actual driver to work on low cpu count machines. Signed-off-by: cpw --- .../net/minecraftforge/fml/ModWorkManager.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/ModWorkManager.java b/src/main/java/net/minecraftforge/fml/ModWorkManager.java index 21c6cda2f..16cabb308 100644 --- a/src/main/java/net/minecraftforge/fml/ModWorkManager.java +++ b/src/main/java/net/minecraftforge/fml/ModWorkManager.java @@ -23,24 +23,26 @@ import net.minecraftforge.fml.loading.FMLConfig; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.concurrent.ConcurrentLinkedDeque; -import java.util.concurrent.Executor; -import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.ForkJoinWorkerThread; +import java.util.concurrent.*; +import java.util.concurrent.locks.LockSupport; import static net.minecraftforge.fml.Logging.LOADING; public class ModWorkManager { private static final Logger LOGGER = LogManager.getLogger(); - + private static final long PARK_TIME = TimeUnit.MILLISECONDS.toNanos(1); public interface DrivenExecutor extends Executor { boolean selfDriven(); boolean driveOne(); default void drive(Runnable ticker) { if (!selfDriven()) { - while (driveOne()) + while (driveOne()) { ticker.run(); + } + } else { + // park for a bit so other threads can schedule + LockSupport.parkNanos(PARK_TIME); } } }