tmf: make latches synchronized in abstract analysis module [bug 485793]
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / analysis / TmfAbstractAnalysisModule.java
index 13ea189a9288f38aabbbc723f26f59172873d324..a1c65f2371c5dc96c7b91f7b4e17448ca47200bc 100644 (file)
@@ -223,8 +223,10 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent
      */
     protected void resetAnalysis() {
         TmfCoreTracer.traceAnalysis(getId(), getTrace(), "reset: ready for execution"); //$NON-NLS-1$
-        fFinishedLatch.countDown();
-        fFinishedLatch = new CountDownLatch(1);
+        synchronized (syncObj) {
+            fFinishedLatch.countDown();
+            fFinishedLatch = new CountDownLatch(1);
+        }
     }
 
     /**
@@ -266,7 +268,9 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent
     public final void cancel() {
         synchronized (syncObj) {
             TmfCoreTracer.traceAnalysis(getId(), getTrace(), "cancelled by application"); //$NON-NLS-1$
-            if (fJob != null && fJob.cancel()) {
+            Job job = fJob;
+            if (job != null) {
+                job.cancel();
                 fAnalysisCancelled = true;
                 setAnalysisCompleted();
             }
@@ -408,8 +412,16 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent
 
     @Override
     public boolean waitForCompletion() {
+        CountDownLatch finishedLatch;
+        boolean started;
+        synchronized (syncObj) {
+            finishedLatch = fFinishedLatch;
+            started = fStarted;
+        }
         try {
-            fFinishedLatch.await();
+            if (started) {
+                finishedLatch.await();
+            }
         } catch (InterruptedException e) {
             Activator.logError("Error while waiting for module completion", e); //$NON-NLS-1$
         }
This page took 0.024396 seconds and 5 git commands to generate.