diff options
| author | 2012-12-06 19:00:57 -0800 | |
|---|---|---|
| committer | 2012-12-06 19:00:57 -0800 | |
| commit | 05989772d5b46cd5328e88d546f04deef39cc3c8 (patch) | |
| tree | 712613768b3e8e60adb7e37aaa0b992c8862d35b /libs/gui/ConsumerBase.cpp | |
| parent | 6d93da465ab8fff02728f268785e59ab86a2a0c2 (diff) | |
| parent | 3ed2736c10efb2f18062591e308036837d9725a4 (diff) | |
am 3ed2736c: am b21a4e3b: ConsumerBase: free buffers outside the lock
* commit '3ed2736c10efb2f18062591e308036837d9725a4':
ConsumerBase: free buffers outside the lock
Diffstat (limited to 'libs/gui/ConsumerBase.cpp')
| -rw-r--r-- | libs/gui/ConsumerBase.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/libs/gui/ConsumerBase.cpp b/libs/gui/ConsumerBase.cpp index 624d7e0156..cfc0293189 100644 --- a/libs/gui/ConsumerBase.cpp +++ b/libs/gui/ConsumerBase.cpp @@ -109,21 +109,35 @@ void ConsumerBase::onFrameAvailable() { } void ConsumerBase::onBuffersReleased() { - Mutex::Autolock lock(mMutex); + sp<GraphicBuffer> bufRefs[BufferQueue::NUM_BUFFER_SLOTS]; + + { // Scope for the lock + Mutex::Autolock lock(mMutex); + + CB_LOGV("onBuffersReleased"); - CB_LOGV("onBuffersReleased"); + if (mAbandoned) { + // Nothing to do if we're already abandoned. + return; + } + + uint32_t mask = 0; + mBufferQueue->getReleasedBuffers(&mask); + for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) { + if (mask & (1 << i)) { + // Grab a local reference to the buffers so that they don't + // get freed while the lock is held. + bufRefs[i] = mSlots[i].mGraphicBuffer; - if (mAbandoned) { - // Nothing to do if we're already abandoned. - return; + freeBufferLocked(i); + } + } } - uint32_t mask = 0; - mBufferQueue->getReleasedBuffers(&mask); + // Clear the local buffer references. This would happen automatically + // when the array gets dtor'd, but I'm doing it explicitly for clarity. for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) { - if (mask & (1 << i)) { - freeBufferLocked(i); - } + bufRefs[i].clear(); } } |