From 39e576457cb40f601f1ad68296f990dc2bf5f759 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 14 Nov 2014 12:30:14 -0500 Subject: [PATCH] tmf: Use a CountDownLatch instead of Object.wait() in TmfEventThread 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 Reviewed-on: https://git.eclipse.org/r/36516 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam --- .../tmf/core/component/TmfEventThread.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/component/TmfEventThread.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/component/TmfEventThread.java index ce0fcd7eb9..fdb8101139 100644 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/component/TmfEventThread.java +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/component/TmfEventThread.java @@ -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$ } -- 2.34.1