From d62734493eb6410a732614bfb956a43284da2b62 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Mon, 4 Jul 2016 15:09:48 -0400 Subject: [PATCH] tmf: Remove redundant booleans in TmfEventRequest The booleans and CountDownLatches do the same thing, they can be merged together. Change-Id: I77e26cbeb7e9166f8997d5a33571f993616c3cb2 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/76551 Reviewed-by: Matthew Khouzam Tested-by: Matthew Khouzam Reviewed-by: Hudson CI --- .../core/building/TmfGraphBuilderModule.java | 2 +- .../request/TmfCoalescedEventRequest.java | 4 +- .../tmf/core/request/TmfEventRequest.java | 59 +++++-------------- 3 files changed, 18 insertions(+), 47 deletions(-) diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/TmfGraphBuilderModule.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/TmfGraphBuilderModule.java index f248f3f990..e63a9364cc 100644 --- a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/TmfGraphBuilderModule.java +++ b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/TmfGraphBuilderModule.java @@ -134,7 +134,7 @@ public abstract class TmfGraphBuilderModule extends TmfAbstractAnalysisModule { } @Override - public void done() { + public synchronized void done() { super.done(); fProvider.done(); } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/request/TmfCoalescedEventRequest.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/request/TmfCoalescedEventRequest.java index 30dc657d99..39ce02fbef 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/request/TmfCoalescedEventRequest.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/request/TmfCoalescedEventRequest.java @@ -244,7 +244,7 @@ public class TmfCoalescedEventRequest extends TmfEventRequest { } @Override - public void start() { + public synchronized void start() { for (ITmfEventRequest request : fRequests) { if (!request.isCompleted()) { request.start(); @@ -254,7 +254,7 @@ public class TmfCoalescedEventRequest extends TmfEventRequest { } @Override - public void done() { + public synchronized void done() { for (ITmfEventRequest request : fRequests) { if (!request.isCompleted()) { request.done(); diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/request/TmfEventRequest.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/request/TmfEventRequest.java index ac040823fa..a4fc176e74 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/request/TmfEventRequest.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/request/TmfEventRequest.java @@ -94,13 +94,11 @@ public abstract class TmfEventRequest implements ITmfEventRequest { /** The number of reads so far */ private int fNbRead; - private final CountDownLatch startedLatch = new CountDownLatch(1); - private final CountDownLatch completedLatch = new CountDownLatch(1); + private final CountDownLatch fStartedLatch = new CountDownLatch(1); + private final CountDownLatch fCompletedLatch = new CountDownLatch(1); - private boolean fRequestRunning; - private boolean fRequestCompleted; - private boolean fRequestFailed; - private boolean fRequestCanceled; + private volatile boolean fRequestFailed = false; + private volatile boolean fRequestCanceled = false; private ITmfFilter fEventFilter; @@ -206,11 +204,6 @@ public abstract class TmfEventRequest implements ITmfEventRequest { fNbRead = 0; fDependencyLevel = dependencyLevel; - fRequestRunning = false; - fRequestCompleted = false; - fRequestFailed = false; - fRequestCanceled = false; - /* Setup the request tracing if it's enabled */ if (TmfCoreTracer.isRequestTraced()) { String type = getClass().getName(); @@ -257,12 +250,12 @@ public abstract class TmfEventRequest implements ITmfEventRequest { @Override public synchronized boolean isRunning() { - return fRequestRunning; + return (fStartedLatch.getCount() <= 0 && fCompletedLatch.getCount() > 0); } @Override public synchronized boolean isCompleted() { - return fRequestCompleted; + return (fCompletedLatch.getCount() <= 0); } @Override @@ -394,42 +387,24 @@ public abstract class TmfEventRequest implements ITmfEventRequest { * If the thread was interrupted while waiting */ public void waitForStart() throws InterruptedException { - while (!fRequestRunning) { - startedLatch.await(); - } + fStartedLatch.await(); } @Override public void waitForCompletion() throws InterruptedException { - while (!fRequestCompleted) { - completedLatch.await(); - } + fCompletedLatch.await(); } @Override - public void start() { - synchronized (this) { - fRequestRunning = true; - } + public synchronized void start() { handleStarted(); - startedLatch.countDown(); + fStartedLatch.countDown(); } @Override - public void done() { - synchronized (this) { - if (!fRequestCompleted) { - fRequestRunning = false; - fRequestCompleted = true; - } else { - return; - } - } - try { - handleCompleted(); - } finally { - completedLatch.countDown(); - } + public synchronized void done() { + handleCompleted(); + fCompletedLatch.countDown(); } /** @@ -437,18 +412,14 @@ public abstract class TmfEventRequest implements ITmfEventRequest { */ @Override public void fail(Exception e) { - synchronized (this) { - fRequestFailed = true; - } + fRequestFailed = true; fFailureCause = e; done(); } @Override public void cancel() { - synchronized (this) { - fRequestCanceled = true; - } + fRequestCanceled = true; done(); } -- 2.34.1