Bug 1306483 - Part 1: use concurrent queue to fix race condition. r=snorp
authorJohn Lin <jolin@mozilla.com>
Thu, 20 Oct 2016 15:25:44 +0800
changeset 319303 77c515e8350a7d07d807fd9e8ac3bbe136043a4a
parent 319302 8a0851bef5398617c915661793f48833af567502
child 319304 9f2f66e3762fac55594ae72c24634b13eea36ab4
push id30869
push userphilringnalda@gmail.com
push dateWed, 26 Oct 2016 04:57:48 +0000
treeherdermozilla-central@9471b3c49b2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1306483
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1306483 - Part 1: use concurrent queue to fix race condition. r=snorp MozReview-Commit-ID: HRus9Sn7k6q
mobile/android/base/java/org/mozilla/gecko/media/Codec.java
--- a/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
@@ -14,16 +14,17 @@ import android.os.TransactionTooLargeExc
 import android.util.Log;
 import android.view.Surface;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.LinkedList;
 import java.util.NoSuchElementException;
 import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 /* package */ final class Codec extends ICodec.Stub implements IBinder.DeathRecipient {
     private static final String LOGTAG = "GeckoRemoteCodec";
     private static final boolean DEBUG = false;
 
     public enum Error {
         DECODE, FATAL
     };
@@ -183,22 +184,23 @@ import java.util.Queue;
             }
         }
 
         private synchronized void reset() {
             mInputSamples.clear();
             mAvailableInputBuffers.clear();
         }
    }
+
     private volatile ICodecCallbacks mCallbacks;
     private AsyncCodec mCodec;
     private InputProcessor mInputProcessor;
     private volatile boolean mFlushing = false;
     private SamplePool mSamplePool;
-    private Queue<Sample> mSentOutputs = new LinkedList<>();
+    private Queue<Sample> mSentOutputs = new ConcurrentLinkedQueue<>();
 
     public synchronized void setCallbacks(ICodecCallbacks callbacks) throws RemoteException {
         mCallbacks = callbacks;
         callbacks.asBinder().linkToDeath(this, 0);
     }
 
     // IBinder.DeathRecipient
     @Override
@@ -340,18 +342,19 @@ import java.util.Queue;
             reportError(Error.FATAL, new Exception("FAIL: input sample queue is full"));
         }
     }
 
     @Override
     public synchronized void releaseOutput(Sample sample) {
         try {
             mSamplePool.recycleOutput(mSentOutputs.remove());
-        } catch (NoSuchElementException e) {
-            Log.e(LOGTAG, "releaseOutput not found: " + sample + "sent: " + mSentOutputs);
+        } catch (Exception e) {
+            Log.e(LOGTAG, "failed to release output:" + sample);
+            e.printStackTrace();
         }
         sample.dispose();
     }
 
     @Override
     public synchronized void release() throws RemoteException {
         if (DEBUG) Log.d(LOGTAG, "release " + this);
         releaseCodec();