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

Commit 209beca0 authored by Mark Urbanus's avatar Mark Urbanus
Browse files

Create VR HWComposer without locks held

Problem:
Surfaceflinger is occassionally deadlocking when switching to VR Mode.

Root-cause:
During the creation of the VR HWComposer through hwbinder,
hwservicemanager notifies surfaceflinger the service is available through a
binder callback. Because Surfaceflinger holds the state-lock during the
HWComposer creation, its possible all of SurfaceFlinger's binder threads are
handling other transactions waiting for the state-lock to be released.
This prevents the hwservicemanager callback ever to be handled resulting in
a deadlock.

Solution:
Don't hold the state-lock when instantiating the VR HWComposer.

Test: Validated deadlocks no longer occur when switching to VR mode.
Bug: 35680107
Change-Id: I932c81fce293a8b57983f4242432b87522ce964c
parent b0254c42
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -176,8 +176,10 @@ SurfaceFlinger::SurfaceFlinger()
        mFrameBuckets(),
        mTotalTime(0),
        mLastSwapTime(0),
        mNumLayers(0),
        mEnterVrMode(false)
        mNumLayers(0)
#ifdef USE_HWC2
        ,mEnterVrMode(false)
#endif
{
    ALOGI("SurfaceFlinger is starting");

@@ -1204,12 +1206,17 @@ void SurfaceFlinger::resetHwc() {
}

void SurfaceFlinger::updateVrMode() {
    {
        Mutex::Autolock _l(mStateLock);
    bool enteringVrMode = mEnterVrMode;
    if (enteringVrMode == mHwc->isUsingVrComposer()) {
        return;
    }
    if (enteringVrMode && !mVrHwc) {
        // Construct new HWComposer without holding any locks.
        mVrHwc = new HWComposer(true);
        ALOGV("Vr HWC created");
    }
    {
        Mutex::Autolock _l(mStateLock);

        if (enteringVrMode) {
            // Start vrflinger thread, if it hasn't been started already.
@@ -1224,11 +1231,6 @@ void SurfaceFlinger::updateVrMode() {
                }
            }

            if (!mVrHwc) {
                mVrHwc = new HWComposer(true);
                ALOGV("Vr HWC created");
            }

            resetHwc();

            mHwc = mVrHwc;