Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b21a4e3b authored by Jamie Gennis's avatar Jamie Gennis
Browse files

ConsumerBase: free buffers outside the lock

This change makes ConsumerBase::onBuffersReleased hold a reference to all its
gralloc buffers until after the mutex is unlocked.  This prevents slow
gralloc::free calls from causing lock contention with rendering threads.

Bug: 7675940
Change-Id: I0ec805d1b612afeeecfffec03f982371d27d93be
parent efd614b8
Loading
Loading
Loading
Loading
+24 −10
Original line number Diff line number Diff line
@@ -109,6 +109,9 @@ void ConsumerBase::onFrameAvailable() {
}

void ConsumerBase::onBuffersReleased() {
    sp<GraphicBuffer> bufRefs[BufferQueue::NUM_BUFFER_SLOTS];

    { // Scope for the lock
        Mutex::Autolock lock(mMutex);

        CB_LOGV("onBuffersReleased");
@@ -122,11 +125,22 @@ void ConsumerBase::onBuffersReleased() {
        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;

                freeBufferLocked(i);
            }
        }
    }

    // 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++) {
        bufRefs[i].clear();
    }
}

void ConsumerBase::abandon() {
    CB_LOGV("abandon");
    Mutex::Autolock lock(mMutex);