OSDN Git Service

Let the dequeue buffer not busy wait
authorChen Bin <bin.chen@intel.com>
Mon, 15 Apr 2013 02:51:18 +0000 (10:51 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 3 Jan 2014 16:54:36 +0000 (00:54 +0800)
BZ:99992

UI thread and Surfaceflinger Thread are in the same process. They have race to map the
same buffer. and may cause Dequeue buffer failed.
Then UI thread will busy wait for dequeue buffer condition for ever, system will always
black screen.
This Patch don't let UI thread busy wait, and free all buffer to let system can recover.

Category: aosp improvement
Domain:  <Graphics.UI>
Origin: internal
Upstream-Candiate:yes

Change-Id: Ia8e8be40ca229b52e7003d49970986f18e89fded
Orig-Change-Id: I4db21deacf56e1abeadb43841ce1a0350b19d66f
Signed-off-by: Shi Yang <yang.a.shi@intel.com>
Signed-off-by: yifeix.xue <yifeix.xue@intel.com>
Signed-off-by: binchen1 <bin.chen@intel.com>
libs/gui/BufferQueue.cpp

index 2aecb67..85f7757 100644 (file)
@@ -33,6 +33,9 @@
 #include <utils/Trace.h>
 #include <utils/CallStack.h>
 
+static const nsecs_t DEQUEUE_TIMEOUT_VALUE = seconds(5);
+
+
 // Macros for including the BufferQueue name in log messages
 #define ST_LOGV(x, ...) ALOGV("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
 #define ST_LOGD(x, ...) ALOGD("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
@@ -368,7 +371,10 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, sp<Fence>* outFence, bool async
                     ST_LOGE("dequeueBuffer: would block! returning an error instead.");
                     return WOULD_BLOCK;
                 }
-                mDequeueCondition.wait(mMutex);
+                if (mDequeueCondition.waitRelative(mMutex, DEQUEUE_TIMEOUT_VALUE)) {
+                    ST_LOGE("dequeueBuffer: time out and will free all buffer!");
+                    freeAllBuffersLocked();
+                }
             }
         }