tmf: Remove redundant booleans in TmfEventRequest
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Mon, 4 Jul 2016 19:09:48 +0000 (15:09 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 8 Jul 2016 01:33:32 +0000 (21:33 -0400)
The booleans and CountDownLatches do the same thing, they can
be merged together.

Change-Id: I77e26cbeb7e9166f8997d5a33571f993616c3cb2
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/76551
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Hudson CI
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/building/TmfGraphBuilderModule.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/request/TmfCoalescedEventRequest.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/request/TmfEventRequest.java

index f248f3f9901213333c0d672120c0e2c2e4c3bbfa..e63a9364ccbdd1592a30d9217710e5539bc21669 100644 (file)
@@ -134,7 +134,7 @@ public abstract class TmfGraphBuilderModule extends TmfAbstractAnalysisModule {
         }
 
         @Override
-        public void done() {
+        public synchronized void done() {
             super.done();
             fProvider.done();
         }
index 30dc657d999f5ce60bc2350bb72ac48e1919d223..39ce02fbef1411a33cb08b9553af88da342fecde 100644 (file)
@@ -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();
index ac040823fac7fb346ecdaa94751300f9f01b885b..a4fc176e74067b7f30e5ee0998e6ca5e9fc1fbb7 100644 (file)
@@ -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();
     }
 
This page took 0.030015 seconds and 5 git commands to generate.