OSDN Git Service

BQ: Avoid unnecessary calls to consumer listener
authorPablo Ceballos <pceballos@google.com>
Tue, 19 Apr 2016 18:33:00 +0000 (11:33 -0700)
committerPablo Ceballos <pceballos@google.com>
Tue, 19 Apr 2016 19:01:00 +0000 (19:01 +0000)
Try to avoid unnecessary calls to the consumer listener's
onBuffersReleased() since they can potentially deadlock.

Bug 28254168

Change-Id: Ib064e5ebe1403a1028589342b3c33e6f40bb54a9

libs/gui/BufferQueueConsumer.cpp
libs/gui/BufferQueueProducer.cpp

index b591c4e..cbc8893 100644 (file)
@@ -622,6 +622,10 @@ status_t BufferQueueConsumer::setMaxAcquiredBufferCount(
             return NO_INIT;
         }
 
+        if (maxAcquiredBuffers == mCore->mMaxAcquiredBufferCount) {
+            return NO_ERROR;
+        }
+
         // The new maxAcquiredBuffers count should not be violated by the number
         // of currently acquired buffers
         int acquiredCount = 0;
index bb8d39b..91ba18d 100644 (file)
@@ -101,6 +101,10 @@ status_t BufferQueueProducer::setMaxDequeuedBufferCount(
             return NO_INIT;
         }
 
+        if (maxDequeuedBuffers == mCore->mMaxDequeuedBufferCount) {
+            return NO_ERROR;
+        }
+
         // The new maxDequeuedBuffer count should not be violated by the number
         // of currently dequeued buffers
         int dequeuedCount = 0;
@@ -175,6 +179,10 @@ status_t BufferQueueProducer::setAsyncMode(bool async) {
             return NO_INIT;
         }
 
+        if (async == mCore->mAsyncMode) {
+            return NO_ERROR;
+        }
+
         if ((mCore->mMaxAcquiredBufferCount + mCore->mMaxDequeuedBufferCount +
                 (async || mCore->mDequeueBufferCannotBlock ? 1 : 0)) >
                 mCore->mMaxBufferCount) {
@@ -199,7 +207,9 @@ status_t BufferQueueProducer::setAsyncMode(bool async) {
         mCore->mAsyncMode = async;
         VALIDATE_CONSISTENCY();
         mCore->mDequeueCondition.broadcast();
-        listener = mCore->mConsumerListener;
+        if (delta < 0) {
+            listener = mCore->mConsumerListener;
+        }
     } // Autolock scope
 
     // Call back without lock held