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();
|
||||
static {
|
||||
configSpec.define("splashscreen", Boolean.TRUE);
|
||||
configSpec.defineInList("side", Dist.CLIENT.name(), Arrays.stream(Dist.values()).map(Enum::name).collect(Collectors.toList()));
|
||||
configSpec.defineInRange("maxframerate", 60, 10, 120);
|
||||
configSpec.defineInRange("minframerate", 60, 10, 120);
|
||||
configSpec.define("maxThreads", -1);
|
||||
}
|
||||
|
||||
private CommentedFileConfig configData;
|
||||
|
@ -70,7 +68,13 @@ public class FMLConfig
|
|||
LOGGER.debug(CORE, "Splash screen is {}", INSTANCE.splashScreenEnabled());
|
||||
}
|
||||
|
||||
public boolean splashScreenEnabled() {
|
||||
return configData.<Boolean>getOptional("splashscreen").orElse(Boolean.FALSE);
|
||||
public static boolean splashScreenEnabled() {
|
||||
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
|
||||
splashscreen = true
|
||||
# max threads for parallel loading : -1 uses Runtime#availableProcessors
|
||||
maxThreads = -1
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package net.minecraftforge.fml;
|
||||
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.forgespi.language.ModFileScanData;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
|
@ -35,7 +36,6 @@ import java.util.Optional;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
@ -56,14 +56,7 @@ public class ModList
|
|||
private final Map<String, ModFileInfo> fileById;
|
||||
private List<ModContainer> mods;
|
||||
private Map<String, ModContainer> indexedMods;
|
||||
private ForkJoinPool modLoadingThreadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), 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;
|
||||
}, null, false);
|
||||
private ForkJoinPool modLoadingThreadPool;
|
||||
private List<ModFileScanData> modFileScanData;
|
||||
|
||||
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).
|
||||
map(ModInfo.class::cast).
|
||||
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)
|
||||
|
@ -91,6 +87,14 @@ public class ModList
|
|||
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()
|
||||
{
|
||||
return modFiles;
|
||||
|
|
Loading…
Reference in a new issue