hardware/interfaces
修订版 | 48ffe289b0b8fb6515f77affbac6a261ef6552fe (tree) |
---|---|
时间 | 2017-09-09 03:51:57 |
作者 | Chia-I Wu <olv@goog...> |
Commiter | Chia-I Wu |
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
@@ -92,6 +92,23 @@ public: | ||
92 | 92 | bool writeQueue(bool* outQueueChanged, uint32_t* outCommandLength, |
93 | 93 | hidl_vec<hidl_handle>* outCommandHandles) |
94 | 94 | { |
95 | + // After data are written to the queue, it may not be read by the | |
96 | + // remote reader when | |
97 | + // | |
98 | + // - the writer does not send them (because of other errors) | |
99 | + // - the hwbinder transaction fails | |
100 | + // - the reader does not read them (because of other errors) | |
101 | + // | |
102 | + // Discard the stale data here. | |
103 | + size_t staleDataSize = mQueue ? mQueue->availableToRead() : 0; | |
104 | + if (staleDataSize > 0) { | |
105 | + ALOGW("discarding stale data from message queue"); | |
106 | + CommandQueueType::MemTransaction tx; | |
107 | + if (mQueue->beginRead(staleDataSize, &tx)) { | |
108 | + mQueue->commitRead(staleDataSize); | |
109 | + } | |
110 | + } | |
111 | + | |
95 | 112 | // write data to queue, optionally resizing it |
96 | 113 | if (mQueue && (mDataMaxSize <= mQueue->getQuantumCount())) { |
97 | 114 | if (!mQueue->write(mData.get(), mDataWritten)) { |