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

Commit a86e8fe5 authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: better session termination naming

- removed unused variable/once used function
- name reflects these are server threads exiting

Bug: 185167543
Test: binderRpcTest
Change-Id: Ib5301132213088ec049bf38fc78372655cdc7d9a
parent cc5b498d
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -329,7 +329,7 @@ bool RpcServer::setupSocketServer(const RpcSocketAddress& addr) {
    return true;
    return true;
}
}


void RpcServer::onSessionTerminating(const sp<RpcSession>& session) {
void RpcServer::onSessionLockedAllServerThreadsEnded(const sp<RpcSession>& session) {
    auto id = session->mId;
    auto id = session->mId;
    LOG_ALWAYS_FATAL_IF(id == std::nullopt, "Server sessions must be initialized with ID");
    LOG_ALWAYS_FATAL_IF(id == std::nullopt, "Server sessions must be initialized with ID");
    LOG_RPC_DETAIL("Dropping session %d", *id);
    LOG_RPC_DETAIL("Dropping session %d", *id);
@@ -341,7 +341,7 @@ void RpcServer::onSessionTerminating(const sp<RpcSession>& session) {
    (void)mSessions.erase(it);
    (void)mSessions.erase(it);
}
}


void RpcServer::onSessionThreadEnding(const sp<RpcSession>& session) {
void RpcServer::onSessionServerThreadEnded(const sp<RpcSession>& session) {
    (void)session;
    (void)session;
    mShutdownCv.notify_all();
    mShutdownCv.notify_all();
}
}
+5 −18
Original line number Original line Diff line number Diff line
@@ -219,23 +219,7 @@ void RpcSession::join(unique_fd client) {
    }
    }


    if (server != nullptr) {
    if (server != nullptr) {
        server->onSessionThreadEnding(sp<RpcSession>::fromExisting(this));
        server->onSessionServerThreadEnded(sp<RpcSession>::fromExisting(this));
    }
}

void RpcSession::terminateLocked() {
    // TODO(b/185167543):
    // - kindly notify other side of the connection of termination (can't be
    // locked)
    // - prevent new client/servers from being added
    // - stop all threads which are currently reading/writing
    // - terminate RpcState?

    if (mTerminated) return;

    sp<RpcServer> server = mForServer.promote();
    if (server) {
        server->onSessionTerminating(sp<RpcSession>::fromExisting(this));
    }
    }
}
}


@@ -359,7 +343,10 @@ bool RpcSession::removeServerConnection(const sp<RpcConnection>& connection) {
        it != mServerConnections.end()) {
        it != mServerConnections.end()) {
        mServerConnections.erase(it);
        mServerConnections.erase(it);
        if (mServerConnections.size() == 0) {
        if (mServerConnections.size() == 0) {
            terminateLocked();
            sp<RpcServer> server = mForServer.promote();
            if (server) {
                server->onSessionLockedAllServerThreadsEnded(sp<RpcSession>::fromExisting(this));
            }
        }
        }
        return true;
        return true;
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -153,8 +153,8 @@ public:


    // internal use only
    // internal use only


    void onSessionTerminating(const sp<RpcSession>& session);
    void onSessionLockedAllServerThreadsEnded(const sp<RpcSession>& session);
    void onSessionThreadEnding(const sp<RpcSession>& session);
    void onSessionServerThreadEnded(const sp<RpcSession>& session);


private:
private:
    friend sp<RpcServer>;
    friend sp<RpcServer>;
+0 −2
Original line number Original line Diff line number Diff line
@@ -144,7 +144,6 @@ private:
    void preJoin(std::thread thread);
    void preJoin(std::thread thread);
    // join on thread passed to preJoin
    // join on thread passed to preJoin
    void join(base::unique_fd client);
    void join(base::unique_fd client);
    void terminateLocked();


    struct RpcConnection : public RefBase {
    struct RpcConnection : public RefBase {
        base::unique_fd fd;
        base::unique_fd fd;
@@ -227,7 +226,6 @@ private:
    // TODO(b/185167543): allow sharing between different sessions in a
    // TODO(b/185167543): allow sharing between different sessions in a
    // process? (or combine with mServerConnections)
    // process? (or combine with mServerConnections)
    std::map<std::thread::id, std::thread> mThreads;
    std::map<std::thread::id, std::thread> mThreads;
    bool mTerminated = false;
};
};


} // namespace android
} // namespace android