Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions org.coreasm.engine/src/org/coreasm/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -987,31 +987,41 @@ public void run() {
*/

case emError:
isBusyLock.lock();
try {
// Throw out all commands except a recovery command
EngineCommand cmd;
while ((cmd = commandQueue.poll()) != null) {
if (cmd.type == EngineCommand.CmdType.ecTerminate) {
next(EngineMode.emTerminating);
lastError = null;
logger.debug("Engine terminated by user command.");
break;
} else if (cmd.type == EngineCommand.CmdType.ecRecover) {
// Recover by going to the idle mode
next(EngineMode.emIdle);
lastError = null;
logger.debug("Engine recovered from error by user command.");
break;
// blocking wait for termination or recover command
// we are not busy while waiting
// throw out all other commands
while (true) {
isBusyLock.lock();
try {
if (commandQueue.isEmpty()) {
engineBusy = false;
isNotBusy.signalAll();
}
}
finally {
isBusyLock.unlock();
}

engineBusy = false;
isNotBusy.signalAll();
}
finally {
isBusyLock.unlock();
EngineCommand cmd = commandQueue.take();
assert engineBusy;

if (cmd.type == EngineCommand.CmdType.ecTerminate) {
next(EngineMode.emTerminating);
lastError = null;
logger.debug("Engine terminated by user command.");
break;
} else if (cmd.type == EngineCommand.CmdType.ecRecover) {
// Recover by going to the idle mode
next(EngineMode.emIdle);
lastError = null;
logger.debug("Engine recovered from error by user command.");
break;
} else {
logger.warn("Ignore user command {}, Engine is in error state and needs to be terminated or reset", cmd.type);
}
}

break;
case emTerminated:
break;
default:
Expand Down