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

Commit f8654a3e authored by Steven Moreland's avatar Steven Moreland Committed by Gerrit Code Review
Browse files

Merge "libbinder: better session termination naming"

parents 3ca69777 a86e8fe5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -329,7 +329,7 @@ bool RpcServer::setupSocketServer(const RpcSocketAddress& addr) {
    return true;
}

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

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

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

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

    // internal use only

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

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

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

} // namespace android