From 48ffe289b0b8fb6515f77affbac6a261ef6552fe Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 8 Sep 2017 11:24:32 -0700 Subject: [PATCH] graphics: discard stale data from message queue Our use of message queues is synchronous. If there are already data in the queue when writeQueue is called, we know they are stale and can be discarded. Bug: 65449888 Test: manual Change-Id: Ie29b8a7386c9733c183a6c3569e3572efa62cbc2 --- .../2.1/default/IComposerCommandBuffer.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/graphics/composer/2.1/default/IComposerCommandBuffer.h b/graphics/composer/2.1/default/IComposerCommandBuffer.h index 9ee5f4f88d..058709c5ed 100644 --- a/graphics/composer/2.1/default/IComposerCommandBuffer.h +++ b/graphics/composer/2.1/default/IComposerCommandBuffer.h @@ -92,6 +92,23 @@ public: bool writeQueue(bool* outQueueChanged, uint32_t* outCommandLength, hidl_vec* outCommandHandles) { + // After data are written to the queue, it may not be read by the + // remote reader when + // + // - the writer does not send them (because of other errors) + // - the hwbinder transaction fails + // - the reader does not read them (because of other errors) + // + // Discard the stale data here. + size_t staleDataSize = mQueue ? mQueue->availableToRead() : 0; + if (staleDataSize > 0) { + ALOGW("discarding stale data from message queue"); + CommandQueueType::MemTransaction tx; + if (mQueue->beginRead(staleDataSize, &tx)) { + mQueue->commitRead(staleDataSize); + } + } + // write data to queue, optionally resizing it if (mQueue && (mDataMaxSize <= mQueue->getQuantumCount())) { if (!mQueue->write(mData.get(), mDataWritten)) {