diff options
author | 2021-05-22 01:07:33 +0000 | |
---|---|---|
committer | 2021-05-22 02:26:03 +0000 | |
commit | ee3f46696a906c2a06443e5eb4501c44ada9f9a6 (patch) | |
tree | f6b73b14e1179df7326450fb060bc5a01613945e /libs/binder/RpcSession.cpp | |
parent | 2b4f380c6548b8c146962eab8bc070e6c3647dc4 (diff) |
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
Diffstat (limited to 'libs/binder/RpcSession.cpp')
-rw-r--r-- | libs/binder/RpcSession.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp index 9f26a33335..7c458c123a 100644 --- a/libs/binder/RpcSession.cpp +++ b/libs/binder/RpcSession.cpp @@ -207,12 +207,19 @@ void RpcSession::join(unique_fd client) { LOG_ALWAYS_FATAL_IF(!removeServerConnection(connection), "bad state: connection object guaranteed to be in list"); + sp<RpcServer> server; { std::lock_guard<std::mutex> _l(mMutex); auto it = mThreads.find(std::this_thread::get_id()); LOG_ALWAYS_FATAL_IF(it == mThreads.end()); it->second.detach(); mThreads.erase(it); + + server = mForServer.promote(); + } + + if (server != nullptr) { + server->onSessionThreadEnding(sp<RpcSession>::fromExisting(this)); } } @@ -314,14 +321,25 @@ bool RpcSession::setupOneSocketClient(const RpcSocketAddress& addr, int32_t id) void RpcSession::addClientConnection(unique_fd fd) { std::lock_guard<std::mutex> _l(mMutex); + + if (mShutdownTrigger == nullptr) { + mShutdownTrigger = FdTrigger::make(); + } + sp<RpcConnection> session = sp<RpcConnection>::make(); session->fd = std::move(fd); mClientConnections.push_back(session); } -void RpcSession::setForServer(const wp<RpcServer>& server, int32_t sessionId) { +void RpcSession::setForServer(const wp<RpcServer>& server, int32_t sessionId, + const std::shared_ptr<FdTrigger>& shutdownTrigger) { + LOG_ALWAYS_FATAL_IF(mForServer.unsafe_get() != nullptr); + LOG_ALWAYS_FATAL_IF(mShutdownTrigger != nullptr); + LOG_ALWAYS_FATAL_IF(shutdownTrigger == nullptr); + mId = sessionId; mForServer = server; + mShutdownTrigger = shutdownTrigger; } sp<RpcSession::RpcConnection> RpcSession::assignServerToThisThread(unique_fd fd) { |