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