X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FProgress.java;h=6f05110e8715305b438258b45cf1674b992a4451;hp=38ce29f9c8b49e6c4a27dd939fbf4d89d330817f;hb=f4053377fa15da2f11e82955bfab86e673fa371c;hpb=451f434bd60a354ae5928f5da36b76f24b7b423b diff --git a/src/be/nikiroo/utils/Progress.java b/src/be/nikiroo/utils/Progress.java index 38ce29f..6f05110 100644 --- a/src/be/nikiroo/utils/Progress.java +++ b/src/be/nikiroo/utils/Progress.java @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; /** * Progress reporting system, possibly nested. @@ -318,8 +317,10 @@ public class Progress { * * @return the children (Who will think of the children??) */ - public Set getChildren() { - return children.keySet(); + public List getChildren() { + synchronized (getLock()) { + return new ArrayList(children.keySet()); + } } /** @@ -359,7 +360,9 @@ public class Progress { * the listener */ public void addProgressListener(ProgressListener l) { - this.listeners.add(l); + synchronized (getLock()) { + this.listeners.add(l); + } } /** @@ -371,7 +374,9 @@ public class Progress { * @return TRUE if it was found (and removed) */ public boolean removeProgressListener(ProgressListener l) { - return this.listeners.remove(l); + synchronized (getLock()) { + return this.listeners.remove(l); + } } /** @@ -408,9 +413,12 @@ public class Progress { public void progress(Progress pg, String name) { synchronized (getLock()) { double total = relativeLocalProgress; - for (Entry entry : children.entrySet()) { - total += (entry.getValue() / (max - min)) - * entry.getKey().getRelativeProgress(); + synchronized (getLock()) { + for (Entry entry : children + .entrySet()) { + total += (entry.getValue() / (max - min)) + * entry.getKey().getRelativeProgress(); + } } setRelativeProgress(pg, name, total); @@ -418,7 +426,9 @@ public class Progress { } }); - this.children.put(progress, weight); + synchronized (getLock()) { + this.children.put(progress, weight); + } } /**