From 2972e82f4ac0f2a12de866b512446d15049617b1 Mon Sep 17 00:00:00 2001 From: Emmanuel Bigeon Date: Sat, 27 Oct 2018 14:17:19 -0400 Subject: [PATCH] fix interlocks Signed-off-by: Emmanuel Bigeon --- .../process/io/ConnectingConsoleInput.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java b/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java index b33dea8..cf83ab3 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java @@ -127,13 +127,13 @@ public final class ConnectingConsoleInput implements ConsoleInput { /** Disconnect the current input. */ public void disconnect() { - synchronized (connectionLock) { - if (connected != null) { - disconnection = true; - synchronized (promptLock) { + synchronized (promptLock) { + synchronized (connectionLock) { + if (connected != null) { + disconnection = true; connected.interruptPrompt(); + connected = null; } - connected = null; } } } @@ -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 { - final String res = connected.prompt(message, - end - System.currentTimeMillis()); synchronized (connectionLock) { + final String res = connected.prompt(message, + end - System.currentTimeMillis()); if (disconnection) { disconnection = false; } else if (prompting) {