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

Commit 2b0ee672 authored by Pawin Vongmasa's avatar Pawin Vongmasa
Browse files

Stop GraphicBufferSource's looper without locking

Before this CL, the following sequence of events could cause a deadlock:
- Binder thread: Acquires the mutex (mMutex) inside release().
- Looper thread: Blocks inside onMessageReceived() as it tries to
acquire the mutex.
- Binder thread: Calls mLooper->stop() inside release(), which waits for
the looper thread to finish executing onMessageReceived().

Test: make cts -j123 && cts-tradefed run cts-dev -m \
CtsMediaTestCases --compatibility:module-arg \
CtsMediaTestCases:include-annotation:\
android.platform.test.annotations.RequiresDevice

Bug: 74170420
Change-Id: Ie63b19107f10937f7a301fe74b38f15076cc0ed9
parent ecff3f95
Loading
Loading
Loading
Loading
+22 −17
Original line number Diff line number Diff line
@@ -421,12 +421,14 @@ Status GraphicBufferSource::stop() {
}

Status GraphicBufferSource::release(){
    sp<ALooper> looper;
    {
        Mutex::Autolock autoLock(mMutex);
        looper = mLooper;
        if (mLooper != NULL) {
            mLooper->unregisterHandler(mReflector->id());
            mReflector.clear();

        mLooper->stop();
            mLooper.clear();
        }

@@ -440,7 +442,10 @@ Status GraphicBufferSource::release(){
        mLatestBuffer.mBuffer.reset();
        mComponent.clear();
        mExecuting = false;

    }
    if (looper != NULL) {
        looper->stop();
    }
    return Status::ok();
}