tmf: Use a CountDownLatch instead of Object.wait() in TmfEventThread
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 14 Nov 2014 17:30:14 +0000 (12:30 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 1 Dec 2014 17:51:12 +0000 (12:51 -0500)
The current way to manage paused requests in TmfEventThread uses
a wait()/notify() on a custom Object. Since this object is not used
for anything else, we can replace its with a CountDownLatch, which
does the same thing without requiring an additional synchronized lock.

Change-Id: Ie69612769e3554d6e71d030230b409d8a0145450
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/36516
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/component/TmfEventThread.java

index ce0fcd7eb9b636d6ed471704de63f795f25ec0a9..fdb81011394d846246a21a6379f8c82db0809518 100644 (file)
@@ -13,6 +13,8 @@
 
 package org.eclipse.tracecompass.internal.tmf.core.component;
 
+import java.util.concurrent.CountDownLatch;
+
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
 import org.eclipse.tracecompass.internal.tmf.core.TmfCoreTracer;
 import org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider;
@@ -55,14 +57,13 @@ public class TmfEventThread implements Runnable {
      */
     private final TmfEventThread  fThread;
 
+    private volatile CountDownLatch fLatch = new CountDownLatch(1);
+
     /**
      * The thread execution state
      */
     private volatile boolean isCompleted = false;
 
-    /** The synchronization object */
-    private final Object fSynchObject = new Object();
-
     /** The flag for suspending a thread */
     private volatile boolean fIsPaused = false;
 
@@ -185,15 +186,9 @@ public class TmfEventThread implements Runnable {
                 }
 
                 // Pause execution if requested
-
                 while (fIsPaused) {
-                    synchronized (fSynchObject) {
-                        try {
-                            fSynchObject.wait();
-                        } catch (InterruptedException e) {
-                            // continue
-                        }
-                    }
+                    CountDownLatch latch = fLatch;
+                    latch.await();
                 }
 
                 // To avoid an unnecessary read passed the last event requested
@@ -236,9 +231,11 @@ public class TmfEventThread implements Runnable {
      */
     public void resume() {
         fIsPaused = false;
-        synchronized (fSynchObject) {
-            fSynchObject.notifyAll();
-        }
+
+        CountDownLatch oldLatch = fLatch;
+        fLatch = new CountDownLatch(1);
+        oldLatch.countDown();
+
         TmfCoreTracer.traceRequest(fRequest.getRequestId(), "RESUMED"); //$NON-NLS-1$
     }
 
This page took 0.027711 seconds and 5 git commands to generate.