Fixes pool size w/ re-add mode 2

This commit is contained in:
Sotr
2018-08-13 08:36:03 +08:00
parent 732cc57ee5
commit 2593ab8eba
2 changed files with 21 additions and 5 deletions

View File

@@ -86,11 +86,14 @@ public abstract class Akari {
case -1:
return;
case 0:
parallelism = 1;
parallelism = 2;
break;
case 1:
parallelism = worlds + 1;
break;
case 2:
default:
parallelism = worlds;
parallelism = worlds * 2;
break;
}
STAGE_TICK = new SuspendableExecutorCompletionService<>(new SuspendableThreadPoolExecutor(parallelism, parallelism,

View File

@@ -151,20 +151,33 @@ public abstract class MixinMinecraftServer {
if (cachedWorldSize != worlds.size()) Akari.resizeTickExecutors((cachedWorldSize = worlds.size()));
switch (AkarinGlobalConfig.parallelMode) {
case 1:
case 2:
default:
// Never tick one world concurrently!
for (int i = 1; i <= cachedWorldSize; ++i) {
for (int i = 0; i < cachedWorldSize; i++) {
// Impl Note:
// Entities ticking: index 1 -> ... -> 0 (parallel)
// World ticking: index 0 -> ... (parallel)
WorldServer entityWorld = worlds.get(i < cachedWorldSize ? i : 0);
int interlace = i + 1;
WorldServer entityWorld = worlds.get(interlace < cachedWorldSize ? interlace : 0);
Akari.STAGE_TICK.submit(() -> {
synchronized (((IMixinWorldServer) entityWorld).lock()) {
tickEntities(entityWorld);
}
}, null/*new TimingSignal(entityWorld, true)*/);
if (AkarinGlobalConfig.parallelMode != 1) {
int fi = i;
Akari.STAGE_TICK.submit(() -> {
WorldServer world = worlds.get(fi);
synchronized (((IMixinWorldServer) world).lock()) {
tickWorld(world);
}
}, null);
}
}
if (AkarinGlobalConfig.parallelMode == 1)
Akari.STAGE_TICK.submit(() -> {
for (int i = 0; i < cachedWorldSize; i++) {
WorldServer world = worlds.get(i);
@@ -174,7 +187,7 @@ public abstract class MixinMinecraftServer {
}
}, null);
for (int i = cachedWorldSize; i -->= 0 ;) {
for (int i = (AkarinGlobalConfig.parallelMode == 1 ? cachedWorldSize + 1 : cachedWorldSize * 2); i --> 0 ;) {
Akari.STAGE_TICK.take();
}