From: Matthew Khouzam Date: Mon, 24 Oct 2016 13:47:55 +0000 (-0400) Subject: tmf: make latches synchronized in abstract analysis module [bug 485793] X-Git-Url: http://git.efficios.com/?p=deliverable%2Ftracecompass.git;a=commitdiff_plain;h=1a01cbfd2acf7daf9b9deaeb1549ead48b47ed17 tmf: make latches synchronized in abstract analysis module [bug 485793] Fixes a build instability caused by schedule (by design) spawning a job that runs asynchronously. This makes cancellation racy since it can occur before said job starts. Change-Id: I93617efb80f4eb196ef0aba5cbe72e67917c876c Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/83786 Reviewed-by: Genevieve Bastien Tested-by: Genevieve Bastien Reviewed-by: Hudson CI Tested-by: Marc-Andre Laperle --- diff --git a/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/analysis/AnalysisModuleTest.java b/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/analysis/AnalysisModuleTest.java index 35001d5e87..1243682b80 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/analysis/AnalysisModuleTest.java +++ b/tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/analysis/AnalysisModuleTest.java @@ -234,7 +234,8 @@ public class AnalysisModuleTest { fail(e.getMessage()); } - assertEquals(Status.OK_STATUS, module.schedule()); + IStatus schedule = module.schedule(); + assertEquals(Status.OK_STATUS, schedule); /* Give the job a chance to start */ try { diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/analysis/TmfAbstractAnalysisModule.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/analysis/TmfAbstractAnalysisModule.java index 13ea189a92..a1c65f2371 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/analysis/TmfAbstractAnalysisModule.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/analysis/TmfAbstractAnalysisModule.java @@ -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$ }