From: Chen Bin Date: Mon, 15 Apr 2013 02:51:18 +0000 (+0800) Subject: Let the dequeue buffer not busy wait X-Git-Tag: android-x86-4.4-r1~9 X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fframeworks-native.git;a=commitdiff_plain;h=2f86af1ae0b780e793e208ae13ce12d7b8ab0ecd Let the dequeue buffer not busy wait 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: Origin: internal Upstream-Candiate:yes Change-Id: Ia8e8be40ca229b52e7003d49970986f18e89fded Orig-Change-Id: I4db21deacf56e1abeadb43841ce1a0350b19d66f Signed-off-by: Shi Yang Signed-off-by: yifeix.xue Signed-off-by: binchen1 --- diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index 2aecb67788..85f7757b53 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -33,6 +33,9 @@ #include #include +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* 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(); + } } }