From ee3f46696a906c2a06443e5eb4501c44ada9f9a6 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Sat, 22 May 2021 01:07:33 +0000 Subject: libbinder: shutdown session threads The last piece to completely shutting down servers (this is in preparation for adding threadpools to server callbacks, which actually need to be shut down during normal usage). Bug: 185167543 Test: binderRpcTest Change-Id: I20d6ac16c58fe6801545fa7be178518201fe075d --- libs/binder/RpcServer.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'libs/binder/RpcServer.cpp') diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp index e3bf2a5e36..bff5543c9b 100644 --- a/libs/binder/RpcServer.cpp +++ b/libs/binder/RpcServer.cpp @@ -192,10 +192,10 @@ bool RpcServer::shutdown() { } mShutdownTrigger->trigger(); - while (mJoinThreadRunning || !mConnectingThreads.empty()) { + while (mJoinThreadRunning || !mConnectingThreads.empty() || !mSessions.empty()) { ALOGI("Waiting for RpcServer to shut down. Join thread running: %d, Connecting threads: " - "%zu", - mJoinThreadRunning, mConnectingThreads.size()); + "%zu, Sessions: %zu", + mJoinThreadRunning, mConnectingThreads.size(), mSessions.size()); mShutdownCv.wait(_l); } @@ -278,7 +278,8 @@ void RpcServer::establishConnection(sp&& server, base::unique_fd clie server->mSessionIdCounter++; session = RpcSession::make(); - session->setForServer(wp(server), server->mSessionIdCounter); + session->setForServer(wp(server), server->mSessionIdCounter, + server->mShutdownTrigger); server->mSessions[server->mSessionIdCounter] = session; } else { @@ -344,6 +345,11 @@ void RpcServer::onSessionTerminating(const sp& session) { (void)mSessions.erase(it); } +void RpcServer::onSessionThreadEnding(const sp& session) { + (void)session; + mShutdownCv.notify_all(); +} + bool RpcServer::hasServer() { LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!"); std::lock_guard _l(mLock); -- cgit v1.2.3-59-g8ed1b