diff options
author | 2016-07-06 09:28:35 +0000 | |
---|---|---|
committer | 2016-07-06 09:43:33 +0000 | |
commit | 95ee651bf734c8dcbfc72dd41b15dc5f3dcdfa02 (patch) | |
tree | 8df33e2e2a9d127007806c4d9e6f8b2905d9c7e5 /src | |
parent | db2df69c475fabe4d3a09c6124d3f75f8cbf441a (diff) |
Experimental UI: make stopUpdateThread() more insisting
The stopUpdateThread() method tries to stop the update thread
by calling the interrupt() and join() methods on that thread.
When getting interrupted while waiting for the thread to join,
do not ignore the exception, instead try again to make sure
we don't leave that method before the other thread is actually
stopped.
While there, also clean up the synchronized blocks for the thread
handling: all blocks that handle multiple global variables like
buildComplete, updateThread, etc, are synchronized while the actual
thread-manipulating operations are outside those blocks.
--
MOS_MIGRATED_REVID=126679343
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java index 166f3c52ee..ee9028139a 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java @@ -311,7 +311,7 @@ public class ExperimentalEventHandler implements EventHandler { } @Subscribe - public void buildComplete(BuildCompleteEvent event) { + public synchronized void buildComplete(BuildCompleteEvent event) { // The final progress bar will flow into the scroll-back buffer, to if treat // it as an event and add a time stamp, if events are supposed to have a time stmap. if (showTimestamp) { @@ -327,7 +327,7 @@ public class ExperimentalEventHandler implements EventHandler { } @Subscribe - public void noBuild(NoBuildEvent event) { + public synchronized void noBuild(NoBuildEvent event) { buildComplete = true; stopUpdateThread(); flushStdOutStdErrBuffers(); @@ -481,15 +481,12 @@ public class ExperimentalEventHandler implements EventHandler { } private void startUpdateThread() { - // Refuse to start an update thread once the build is complete; such a situation might - // arise if the completion of the build is reported (shortly) before the completion of - // the last action is reported. - if (buildComplete) { - return; - } Thread threadToStart = null; synchronized (this) { - if (updateThread == null) { + // Refuse to start an update thread once the build is complete; such a situation might + // arise if the completion of the build is reported (shortly) before the completion of + // the last action is reported. + if (!buildComplete && updateThread == null) { final ExperimentalEventHandler eventHandler = this; updateThread = new Thread( @@ -512,9 +509,9 @@ public class ExperimentalEventHandler implements EventHandler { }); threadToStart = updateThread; } - if (threadToStart != null) { - threadToStart.start(); - } + } + if (threadToStart != null) { + threadToStart.start(); } } @@ -528,10 +525,17 @@ public class ExperimentalEventHandler implements EventHandler { } if (threadToWaitFor != null) { threadToWaitFor.interrupt(); - try { - threadToWaitFor.join(); - } catch (InterruptedException e) { - // Ignore + boolean gotInterrupted = false; + while (true) { + try { + threadToWaitFor.join(); + break; + } catch (InterruptedException e) { + gotInterrupted = true; + } + } + if (gotInterrupted) { + Thread.currentThread().interrupt(); } } } |