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

Commit 79ad3676 authored by Noelle Scobie's avatar Noelle Scobie
Browse files

Process pending tasks before shutting down RenderEngineThreaded

This ensures texture destruction doesn't race during shutdown, which
surfaced when adding RE's Vulkan backends to librenderengine_bench

Bug: b/425756879
Test: Vulkan backends crash librenderengine_test without this change
Flag: EXEMPT RE instances are only destroyed in tests and benchmarks
Change-Id: Iacaa875c598a54f5e4d5245144af0fcf385e202f
parent 86302813
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -97,7 +97,6 @@ void RenderEngineThreaded::threadMain(CreateInstanceFactory factory) NO_THREAD_S
    }
    mInitializedCondition.notify_all();

    while (mRunning) {
    const auto getNextTask = [this]() -> std::optional<Work> {
        std::scoped_lock lock(mThreadMutex);
        if (!mFunctionCalls.empty()) {
@@ -108,6 +107,8 @@ void RenderEngineThreaded::threadMain(CreateInstanceFactory factory) NO_THREAD_S
        return std::nullopt;
    };

    // process any tasks until shutdown
    while (mRunning) {
        const auto task = getNextTask();

        if (task) {
@@ -120,6 +121,14 @@ void RenderEngineThreaded::threadMain(CreateInstanceFactory factory) NO_THREAD_S
        });
    }

    // RenderEngine is only shutdown gracefully during tests / benchmarks, where cleanup tasks (e.g.
    // unmapExternalTextureBuffer) need to be processed before destroying RE's GPU contexts, but
    // those tasks may race against the main loop above exiting during shutdown. Processing any
    // remaining tasks here ensures cleanup tasks are properly handled.
    while (auto task = getNextTask()) {
        (*task)(*mRenderEngine);
    }

    // we must release the RenderEngine on the thread that created it
    mRenderEngine.reset();
}