Use a configuration value for the thread count, make it default to
availableProcessors when set to <=0 (default value is -1) Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
64f69cf5c9
commit
b28a418bd9
3 changed files with 24 additions and 14 deletions
|
@ -39,9 +39,7 @@ public class FMLConfig
|
||||||
private static ConfigSpec configSpec = new ConfigSpec();
|
private static ConfigSpec configSpec = new ConfigSpec();
|
||||||
static {
|
static {
|
||||||
configSpec.define("splashscreen", Boolean.TRUE);
|
configSpec.define("splashscreen", Boolean.TRUE);
|
||||||
configSpec.defineInList("side", Dist.CLIENT.name(), Arrays.stream(Dist.values()).map(Enum::name).collect(Collectors.toList()));
|
configSpec.define("maxThreads", -1);
|
||||||
configSpec.defineInRange("maxframerate", 60, 10, 120);
|
|
||||||
configSpec.defineInRange("minframerate", 60, 10, 120);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommentedFileConfig configData;
|
private CommentedFileConfig configData;
|
||||||
|
@ -70,7 +68,13 @@ public class FMLConfig
|
||||||
LOGGER.debug(CORE, "Splash screen is {}", INSTANCE.splashScreenEnabled());
|
LOGGER.debug(CORE, "Splash screen is {}", INSTANCE.splashScreenEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean splashScreenEnabled() {
|
public static boolean splashScreenEnabled() {
|
||||||
return configData.<Boolean>getOptional("splashscreen").orElse(Boolean.FALSE);
|
return INSTANCE.configData.<Boolean>getOptional("splashscreen").orElse(Boolean.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int loadingThreadCount() {
|
||||||
|
int val = INSTANCE.configData.get("maxThreads");
|
||||||
|
if (val <= 0) return Runtime.getRuntime().availableProcessors();
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
# does the splashscreen run
|
# does the splashscreen run
|
||||||
splashscreen = true
|
splashscreen = true
|
||||||
|
# max threads for parallel loading : -1 uses Runtime#availableProcessors
|
||||||
|
maxThreads = -1
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package net.minecraftforge.fml;
|
package net.minecraftforge.fml;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.loading.FMLConfig;
|
||||||
import net.minecraftforge.forgespi.language.ModFileScanData;
|
import net.minecraftforge.forgespi.language.ModFileScanData;
|
||||||
import net.minecraftforge.fml.loading.FMLLoader;
|
import net.minecraftforge.fml.loading.FMLLoader;
|
||||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||||
|
@ -35,7 +36,6 @@ import java.util.Optional;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.concurrent.ForkJoinWorkerThread;
|
import java.util.concurrent.ForkJoinWorkerThread;
|
||||||
import java.util.concurrent.FutureTask;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -56,14 +56,7 @@ public class ModList
|
||||||
private final Map<String, ModFileInfo> fileById;
|
private final Map<String, ModFileInfo> fileById;
|
||||||
private List<ModContainer> mods;
|
private List<ModContainer> mods;
|
||||||
private Map<String, ModContainer> indexedMods;
|
private Map<String, ModContainer> indexedMods;
|
||||||
private ForkJoinPool modLoadingThreadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), pool ->
|
private ForkJoinPool modLoadingThreadPool;
|
||||||
{
|
|
||||||
ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
|
|
||||||
thread.setName("modloading-worker-" + thread.getPoolIndex());
|
|
||||||
// The default sets it to the SystemClassloader, so copy the current one.
|
|
||||||
thread.setContextClassLoader(Thread.currentThread().getContextClassLoader());
|
|
||||||
return thread;
|
|
||||||
}, null, false);
|
|
||||||
private List<ModFileScanData> modFileScanData;
|
private List<ModFileScanData> modFileScanData;
|
||||||
|
|
||||||
private ModList(final List<ModFile> modFiles, final List<ModInfo> sortedList)
|
private ModList(final List<ModFile> modFiles, final List<ModInfo> sortedList)
|
||||||
|
@ -75,6 +68,9 @@ public class ModList
|
||||||
this.fileById = this.modFiles.stream().map(ModFileInfo::getMods).flatMap(Collection::stream).
|
this.fileById = this.modFiles.stream().map(ModFileInfo::getMods).flatMap(Collection::stream).
|
||||||
map(ModInfo.class::cast).
|
map(ModInfo.class::cast).
|
||||||
collect(Collectors.toMap(ModInfo::getModId, ModInfo::getOwningFile));
|
collect(Collectors.toMap(ModInfo::getModId, ModInfo::getOwningFile));
|
||||||
|
final int loadingThreadCount = FMLConfig.loadingThreadCount();
|
||||||
|
LOGGER.debug(LOADING, "Using {} threads for parallel mod-loading", loadingThreadCount);
|
||||||
|
modLoadingThreadPool = new ForkJoinPool(loadingThreadCount, ModList::newForkJoinWorkerThread, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ModList of(List<ModFile> modFiles, List<ModInfo> sortedList)
|
public static ModList of(List<ModFile> modFiles, List<ModInfo> sortedList)
|
||||||
|
@ -91,6 +87,14 @@ public class ModList
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ForkJoinWorkerThread newForkJoinWorkerThread(ForkJoinPool pool) {
|
||||||
|
ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
|
||||||
|
thread.setName("modloading-worker-" + thread.getPoolIndex());
|
||||||
|
// The default sets it to the SystemClassloader, so copy the current one.
|
||||||
|
thread.setContextClassLoader(Thread.currentThread().getContextClassLoader());
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ModFileInfo> getModFiles()
|
public List<ModFileInfo> getModFiles()
|
||||||
{
|
{
|
||||||
return modFiles;
|
return modFiles;
|
||||||
|
|
Loading…
Reference in a new issue