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,13 +127,13 @@ public final class ConnectingConsoleInput implements ConsoleInput {
/** Disconnect the current input. */ /** Disconnect the current input. */
public void disconnect() { public void disconnect() {
synchronized (connectionLock) { synchronized (promptLock) {
if (connected != null) { synchronized (connectionLock) {
disconnection = true; if (connected != null) {
synchronized (promptLock) { disconnection = true;
connected.interruptPrompt(); connected.interruptPrompt();
connected = null;
} }
connected = null;
} }
} }
} }
@ -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 {
final String res = connected.prompt(message,
end - System.currentTimeMillis());
synchronized (connectionLock) { synchronized (connectionLock) {
final String res = connected.prompt(message,
end - System.currentTimeMillis());
if (disconnection) { if (disconnection) {
disconnection = false; disconnection = false;
} else if (prompting) { } else if (prompting) {