Commit 971ef221 authored by Max Lv's avatar Max Lv

fix a data race

parent c35a92a9
...@@ -57,7 +57,10 @@ object Console { ...@@ -57,7 +57,10 @@ object Console {
.open(new OnCommandResultListener { .open(new OnCommandResultListener {
override def onCommandResult(commandCode: Int, exitCode: Int, override def onCommandResult(commandCode: Int, exitCode: Int,
output: util.List[String]) { output: util.List[String]) {
if (exitCode < 0) shell = null if (exitCode < 0) {
shell.close()
shell = null
}
} }
}) })
} }
...@@ -82,8 +85,9 @@ object Console { ...@@ -82,8 +85,9 @@ object Console {
if (shell == null) { if (shell == null) {
openShell() openShell()
} }
shell.addCommand(commands) val ts = shell
shell.waitForIdle() ts.addCommand(commands)
ts.waitForIdle()
} }
def runRootCommand(command: String): String = runRootCommand(Array(command)) def runRootCommand(command: String): String = runRootCommand(Array(command))
...@@ -95,11 +99,13 @@ object Console { ...@@ -95,11 +99,13 @@ object Console {
if (rootShell == null) { if (rootShell == null) {
openRootShell() openRootShell()
} }
val ts = rootShell
val sb = new StringBuilder val sb = new StringBuilder
rootShell.addCommand(commands, 0, new OnCommandResultListener { ts.addCommand(commands, 0, new OnCommandResultListener {
override def onCommandResult(commandCode: Int, exitCode: Int, override def onCommandResult(commandCode: Int, exitCode: Int,
output: util.List[String]) { output: util.List[String]) {
if (exitCode < 0) { if (exitCode < 0) {
rootShell.close()
rootShell = null rootShell = null
} else { } else {
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
...@@ -107,7 +113,7 @@ object Console { ...@@ -107,7 +113,7 @@ object Console {
} }
} }
}) })
if (rootShell.waitForIdle()) sb.toString() if (ts.waitForIdle()) sb.toString()
else null else null
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment