fix interlocks

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2018-10-27 14:17:19 -04:00
parent 0ab39b24f6
commit 2972e82f4a

View File

@ -127,16 +127,16 @@ public final class ConnectingConsoleInput implements ConsoleInput {
/** Disconnect the current input. */ /** Disconnect the current input. */
public void disconnect() { public void disconnect() {
synchronized (promptLock) {
synchronized (connectionLock) { synchronized (connectionLock) {
if (connected != null) { if (connected != null) {
disconnection = true; disconnection = true;
synchronized (promptLock) {
connected.interruptPrompt(); connected.interruptPrompt();
}
connected = null; connected = null;
} }
} }
} }
}
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */ * @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */
@ -191,7 +191,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
if (!prompting) { if (!prompting) {
return null; return null;
} }
boolean connect = true; boolean connect;
synchronized (connectionLock) { synchronized (connectionLock) {
connect = connected != null; connect = connected != null;
} }
@ -234,7 +234,11 @@ public final class ConnectingConsoleInput implements ConsoleInput {
if (!prompting) { if (!prompting) {
return null; return null;
} }
if (connected == null) { boolean connect;
synchronized (connectionLock) {
connect = connected != null;
}
if (!connect) {
try { try {
promptLock.wait(timeout); promptLock.wait(timeout);
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
@ -242,9 +246,9 @@ public final class ConnectingConsoleInput implements ConsoleInput {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} else { } else {
synchronized (connectionLock) {
final String res = connected.prompt(message, final String res = connected.prompt(message,
end - System.currentTimeMillis()); end - System.currentTimeMillis());
synchronized (connectionLock) {
if (disconnection) { if (disconnection) {
disconnection = false; disconnection = false;
} else if (prompting) { } else if (prompting) {