From d2d5a64aa21cfc548c8c8333d1b36979e5e5a640 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 11 Mar 2013 17:59:59 -0700 Subject: [PATCH] workaround a deadlock when taking screenshots into a surface When disconnecting from BufferQueue, we now drain the queue except the head (which means in the screenshot case we won't have to block, but we might not have a buffer to show, this will appear as an error in the log). Bug: 8362363 Change-Id: If80989aac3c917beea2ebddf3cbb502849d394da --- libs/gui/BufferQueue.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index d93c06717..41ee1be92 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -995,7 +995,7 @@ void BufferQueue::freeAllBuffersExceptHeadLocked() { } status_t BufferQueue::drainQueueLocked() { - while (mSynchronousMode && !mQueue.isEmpty()) { + while (mSynchronousMode && mQueue.size() > 1) { mDequeueCondition.wait(mMutex); if (mAbandoned) { ST_LOGE("drainQueueLocked: BufferQueue has been abandoned!"); @@ -1012,7 +1012,7 @@ status_t BufferQueue::drainQueueLocked() { status_t BufferQueue::drainQueueAndFreeBuffersLocked() { status_t err = drainQueueLocked(); if (err == NO_ERROR) { - if (mSynchronousMode) { + if (mQueue.empty()) { freeAllBuffersLocked(); } else { freeAllBuffersExceptHeadLocked();