diff options
author | 2021-05-25 02:25:07 +0000 | |
---|---|---|
committer | 2021-05-25 02:25:07 +0000 | |
commit | 45916263e09d63771c7cc9748f134b45de563c05 (patch) | |
tree | 32c95fb6ad485a1b7edfc686b43f579fe8a90c25 /libs/binder/RpcSession.cpp | |
parent | eaa613b4b3cded9a8ed11c02b7fcf66770a5b397 (diff) | |
parent | 6c6cd10c01a613f20a00a8e8394b5977c9e0ff33 (diff) |
Merge "libbinder: shutdown session threads" am: c1500480cb am: e8990d0d2a am: bf6d2a9c43 am: 6c6cd10c01
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1716214
Change-Id: I02b7a1f5cf7fef32a5c88983f63b83dfc0497306
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) { |