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

Commit 5058fa02 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "SurfaceFlinger: Prevent deadlock when destroying Client."

parents 9a633012 5e8e1f00
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -47,12 +47,21 @@ Client::Client(const sp<SurfaceFlinger>& flinger, const sp<Layer>& parentLayer)

Client::~Client()
{
    // We need to post a message to remove our remaining layers rather than
    // do so directly by acquiring the SurfaceFlinger lock. If we were to
    // attempt to directly call the lock it becomes effectively impossible
    // to use sp<Client> while holding the SF lock as descoping it could
    // then trigger a dead-lock.

    const size_t count = mLayers.size();
    for (size_t i=0 ; i<count ; i++) {
        sp<Layer> l = mLayers.valueAt(i).promote();
        if (l != nullptr) {
            mFlinger->removeLayer(l);
        if (l == nullptr) {
            continue;
        }
        mFlinger->postMessageAsync(new LambdaMessage([flinger = mFlinger, l]() {
            flinger->removeLayer(l);
        }));
    }
}