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

Commit 4f3ff0fa authored by Steven Moreland's avatar Steven Moreland Committed by Android (Google) Code Review
Browse files

Merge "Remove unused IPCThreadState::shutdown." into main

parents 831e5f85 e76effb9
Loading
Loading
Loading
Loading
+18 −22
Original line number Diff line number Diff line
@@ -334,7 +334,6 @@ static pthread_mutex_t gTLSMutex = PTHREAD_MUTEX_INITIALIZER;
LIBBINDER_IGNORE_END()
static std::atomic<bool> gHaveTLS(false);
static pthread_key_t gTLS = 0;
static std::atomic<bool> gShutdown = false;
static std::atomic<bool> gDisableBackgroundScheduling = false;

IPCThreadState* IPCThreadState::self()
@@ -347,12 +346,6 @@ restart:
        return new IPCThreadState;
    }

    // Racey, heuristic test for simultaneous shutdown.
    if (gShutdown.load(std::memory_order_relaxed)) {
        ALOGW("Calling IPCThreadState::self() during shutdown is dangerous, expect a crash.\n");
        return nullptr;
    }

    pthread_mutex_lock(&gTLSMutex);
    if (!gHaveTLS.load(std::memory_order_relaxed)) {
        int key_create_value = pthread_key_create(&gTLS, threadDestructor);
@@ -378,21 +371,24 @@ IPCThreadState* IPCThreadState::selfOrNull()
    return nullptr;
}

void IPCThreadState::shutdown()
{
    gShutdown.store(true, std::memory_order_relaxed);

    if (gHaveTLS.load(std::memory_order_acquire)) {
        // XXX Need to wait for all thread pool threads to exit!
        IPCThreadState* st = (IPCThreadState*)pthread_getspecific(gTLS);
        if (st) {
            delete st;
            pthread_setspecific(gTLS, nullptr);
        }
        pthread_key_delete(gTLS);
        gHaveTLS.store(false, std::memory_order_release);
    }
}
// This code used to be responsible for deleting the TLS, but we keep it
// forever, since binder threads would often race process destruction.
// b/77934844. Keeping a few lines here for visibility of the history.
// IPCThreadState is actually stored in threadDestructor.
//
// void IPCThreadState::shutdown()
// {
//     if (gHaveTLS.load(std::memory_order_acquire)) {
//         // XXX Need to wait for all thread pool threads to exit!
//         IPCThreadState* st = (IPCThreadState*)pthread_getspecific(gTLS);
//         if (st) {
//             delete st;
//             pthread_setspecific(gTLS, nullptr);
//         }
//         pthread_key_delete(gTLS);
//         gHaveTLS.store(false, std::memory_order_release);
//     }
// }

void IPCThreadState::disableBackgroundScheduling(bool disable)
{
+0 −2
Original line number Diff line number Diff line
@@ -180,8 +180,6 @@ public:
    [[nodiscard]] status_t addFrozenStateChangeCallback(int32_t handle, BpBinder* proxy);
    [[nodiscard]] status_t removeFrozenStateChangeCallback(int32_t handle, BpBinder* proxy);

    LIBBINDER_EXPORTED static void shutdown();

    // Call this to disable switching threads to background scheduling when
    // receiving incoming IPC calls.  This is specifically here for the
    // Android system process, since it expects to have background apps calling