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 <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/83786
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Hudson CI
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
- assertEquals(Status.OK_STATUS, module.schedule());
+ IStatus schedule = module.schedule();
+ assertEquals(Status.OK_STATUS, schedule);
/* Give the job a chance to start */
try {
/* Give the job a chance to start */
try {
*/
protected void resetAnalysis() {
TmfCoreTracer.traceAnalysis(getId(), getTrace(), "reset: ready for execution"); //$NON-NLS-1$
*/
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);
+ }
public final void cancel() {
synchronized (syncObj) {
TmfCoreTracer.traceAnalysis(getId(), getTrace(), "cancelled by application"); //$NON-NLS-1$
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();
}
fAnalysisCancelled = true;
setAnalysisCompleted();
}
@Override
public boolean waitForCompletion() {
@Override
public boolean waitForCompletion() {
+ CountDownLatch finishedLatch;
+ boolean started;
+ synchronized (syncObj) {
+ finishedLatch = fFinishedLatch;
+ started = fStarted;
+ }
- fFinishedLatch.await();
+ if (started) {
+ finishedLatch.await();
+ }
} catch (InterruptedException e) {
Activator.logError("Error while waiting for module completion", e); //$NON-NLS-1$
}
} catch (InterruptedException e) {
Activator.logError("Error while waiting for module completion", e); //$NON-NLS-1$
}