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

Commit 2d659286 authored by Jamie Gennis's avatar Jamie Gennis Committed by Android Git Automerger
Browse files

am 2e59d2c3: DO NOT MERGE GraphicBufferAllocator: make frees async

* commit '2e59d2c3':
  DO NOT MERGE GraphicBufferAllocator: make frees async
parents 3ed2736c 2e59d2c3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ private:
    static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList;
    
    friend class Singleton<GraphicBufferAllocator>;
    friend class BufferLiberatorThread;
    GraphicBufferAllocator();
    ~GraphicBufferAllocator();
    
+55 −11
Original line number Diff line number Diff line
@@ -129,21 +129,65 @@ status_t GraphicBufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat forma
    return err;
}

status_t GraphicBufferAllocator::free(buffer_handle_t handle)
class BufferLiberatorThread : public Thread {
public:

    static void queueCaptiveBuffer(buffer_handle_t handle) {
        static sp<BufferLiberatorThread> thread(new BufferLiberatorThread);
        static bool running = false;
        if (!running) {
            thread->run("BufferLiberator");
            running = true;
        }
        {
    ATRACE_CALL();
    status_t err;
            Mutex::Autolock lock(thread->mMutex);
            thread->mQueue.push_back(handle);
            thread->mCondition.signal();
        }
    }

    err = mAllocDev->free(mAllocDev, handle);
private:

    BufferLiberatorThread() {}

    virtual bool threadLoop() {
        buffer_handle_t handle;
        {
            Mutex::Autolock lock(mMutex);
            while (mQueue.isEmpty()) {
                mCondition.wait(mMutex);
            }
            handle = mQueue[0];
            mQueue.removeAt(0);
        }

        status_t err;
        GraphicBufferAllocator& gba(GraphicBufferAllocator::get());
        { // Scope for tracing
            ATRACE_NAME("gralloc::free");
            err = gba.mAllocDev->free(gba.mAllocDev, handle);
        }
        ALOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err));

        if (err == NO_ERROR) {
        Mutex::Autolock _l(sLock);
        KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
            Mutex::Autolock _l(GraphicBufferAllocator::sLock);
            KeyedVector<buffer_handle_t, GraphicBufferAllocator::alloc_rec_t>&
                    list(GraphicBufferAllocator::sAllocList);
            list.removeItem(handle);
        }

    return err;
        return true;
    }

    Vector<buffer_handle_t> mQueue;
    Condition mCondition;
    Mutex mMutex;
};

status_t GraphicBufferAllocator::free(buffer_handle_t handle)
{
    BufferLiberatorThread::queueCaptiveBuffer(handle);
    return NO_ERROR;
}

// ---------------------------------------------------------------------------