Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
experimental UI: move stopUpdateThread() out of synchronized, again
Browse files Browse the repository at this point in the history
The experimental UI uses a thread to regularly update itself to reflect time-based
changes. As that that thread has to call synchronized methods any waiting for it to
finish has to happen outside any synchronized block. Unfortunately, 9e0308e accidentally
moved the stopUpdateThread() in buildComplete() into the synchronized block, thus giving
an opportunity for deadlocks. Move it out again.

Also, as the accounting for pending transports now happens in synchronized methods in
the state tracker, the buildEventTransportClosed() method does not have to be synchronized
any more---thus eliminating the second deadlock opportunity.

Change-Id: Icacb2ee70f4bedde1c1aac2bcfefc6fabf42fdd3
PiperOrigin-RevId: 158537844
  • Loading branch information
aehlig authored and katre committed Jun 9, 2017
1 parent b6ea82a commit 6802831
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ public void progressReceiverAvailable(ExecutionProgressReceiverAvailableEvent ev
public 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 timestamp, if events are supposed to have a timestmap.
boolean done = false;
synchronized (this) {
stateTracker.buildComplete(event);
ignoreRefreshLimitOnce();
Expand All @@ -455,10 +456,13 @@ public void buildComplete(BuildCompleteEvent event) {
// upload happening.
if (stateTracker.pendingTransports() == 0) {
buildComplete = true;
stopUpdateThread();
flushStdOutStdErrBuffers();
done = true;
}
}
if (done) {
stopUpdateThread();
flushStdOutStdErrBuffers();
}
}

@Subscribe
Expand Down Expand Up @@ -574,7 +578,7 @@ public synchronized void buildEventTransportsAnnounced(AnnounceBuildEventTranspo
}

@Subscribe
public synchronized void buildEventTransportClosed(BuildEventTransportClosedEvent event) {
public void buildEventTransportClosed(BuildEventTransportClosedEvent event) {
stateTracker.buildEventTransportClosed(event);
if (debugAllEvents) {
this.handle(Event.info(null, "Transport " + event.transport().name() + " closed"));
Expand Down Expand Up @@ -721,6 +725,11 @@ public void run() {
}
}

/**
* Stop the update thread and wait for it to terminate. As the update thread, which is a separate
* thread, might have to call a synchronized method between being interrupted and terminating, DO
* NOT CALL from a SYNCHRONIZED block, as this will give the opportunity for dead locks.
*/
private void stopUpdateThread() {
Thread threadToWaitFor = null;
synchronized (this) {
Expand Down

0 comments on commit 6802831

Please sign in to comment.