Fix data race in MultiProgressMonitor

This is work related to [1] and [2]. Synchronizing on different objects
(Task vs Monitor) doesn't have much sense as it results (sooner or
later) in deadlocks. This is an attempt to synchronize on monitor object
only (note that Task.getCount() is called from outside the monitor when
processing is basically done).

[1] https://gerrit-review.googlesource.com/#/c/87442/
[2] https://gerrit-review.googlesource.com/#/c/91132/
Change-Id: I99b5da03d5d9ecc9a2fa0d6ca022d6e026d45aba
This commit is contained in:
Jacek Centkowski
2016-11-15 18:49:00 +01:00
parent 4c24c11a4c
commit 331e98b37e
2 changed files with 8 additions and 5 deletions

View File

@@ -81,7 +81,7 @@ public class MultiProgressMonitor {
@Override
public void update(final int completed) {
boolean w = false;
synchronized (this) {
synchronized (MultiProgressMonitor.this) {
count += completed;
if (total != UNKNOWN) {
int percent = count * 100 / total;
@@ -124,8 +124,10 @@ public class MultiProgressMonitor {
return false;
}
public synchronized int getCount() {
return count;
public int getCount() {
synchronized(MultiProgressMonitor.this) {
return count;
}
}
}