- Reverting r34697 for now, it breaks Developer Mode (functionality like Add Card To Hand, Add Card To Play, Setup Game State, etc.) and thus hinders proper debugging of the game in specific situations.

- Please feel free to revert this commit to continue working on the single thread executor project and then recommit once it no longer breaks dev mode.
This commit is contained in:
Agetian
2017-07-11 06:41:21 +00:00
parent aa974352c5
commit b69b6f1097
3 changed files with 5 additions and 38 deletions

View File

@@ -20,10 +20,8 @@ public class ThreadUtil {
}
}
// Use a single game thread, rather than a pool of them, because when something
// needs to execute on the game thread, it's because it's not thread safe.
private final static ExecutorService gameThread = Executors.newSingleThreadExecutor(new WorkerThreadFactory("Game"));
private static ExecutorService getGameThreadPool() { return gameThread; }
private final static ExecutorService gameThreadPool = Executors.newCachedThreadPool(new WorkerThreadFactory("Game"));
private static ExecutorService getGameThreadPool() { return gameThreadPool; }
private final static ScheduledExecutorService scheduledPool = Executors.newScheduledThreadPool(2, new WorkerThreadFactory("Delayed"));
private static ScheduledExecutorService getScheduledPool() { return scheduledPool; }

View File

@@ -298,7 +298,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
// System.out.println("Chosen sa=" + chosen + " of " + chosen.getHostCard() + " to pay mana");
locked = true;
runOnGameThread(game, new Runnable() {
game.getAction().invoke(new Runnable() {
@Override
public void run() {
HumanPlay.playSpellAbility(getController(), chosen.getActivatingPlayer(), chosen);
@@ -390,7 +390,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
}
};
//must run in game thread as certain payment actions can only be automated there
runOnGameThread(game, new Runnable() {
game.getAction().invoke(new Runnable() {
@Override
public void run() {
runAsAi(proc);

View File

@@ -4,23 +4,14 @@ import java.util.concurrent.CountDownLatch;
import forge.FThreads;
import forge.error.BugReporter;
import forge.game.Game;
import forge.player.PlayerControllerHuman;
import forge.util.ThreadUtil;
public abstract class InputSyncronizedBase extends InputBase implements InputSynchronized {
private static final long serialVersionUID = 8756177361251703052L;
private CountDownLatch cdlDone;
private boolean waitingOnGameThread;
private Runnable runnableToRun;
private final CountDownLatch cdlDone;
public InputSyncronizedBase(final PlayerControllerHuman controller) {
super(controller);
reset();
}
private void reset() {
cdlDone = new CountDownLatch(1);
}
@@ -40,30 +31,8 @@ public abstract class InputSyncronizedBase extends InputBase implements InputSyn
}
public void showAndWait() {
waitingOnGameThread = ThreadUtil.isGameThread();
getController().getInputQueue().setInput(this);
awaitLatchRelease();
while (runnableToRun != null) {
Runnable r = runnableToRun;
runnableToRun = null;
reset();
r.run();
awaitLatchRelease();
}
}
protected final void runOnGameThread(Game game, Runnable r) {
if (waitingOnGameThread) {
runnableToRun = r;
cdlDone.countDown();
return;
}
game.getAction().invoke(r);
}
protected final void stop() {