blob: ac7544fde8d75702297f7e93de27ab41e5f3bd8a [file] [log] [blame]
Steven Morelandbdb53ab2021-05-05 17:57:41 +00001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "RpcSession"
18
19#include <binder/RpcSession.h>
20
21#include <inttypes.h>
Steven Moreland4ec3c432021-05-20 00:32:47 +000022#include <poll.h>
Steven Morelandbdb53ab2021-05-05 17:57:41 +000023#include <unistd.h>
24
25#include <string_view>
26
Steven Moreland4ec3c432021-05-20 00:32:47 +000027#include <android-base/macros.h>
Steven Morelandbdb53ab2021-05-05 17:57:41 +000028#include <binder/Parcel.h>
Steven Morelandee78e762021-05-05 21:12:51 +000029#include <binder/RpcServer.h>
Steven Morelandbdb53ab2021-05-05 17:57:41 +000030#include <binder/Stability.h>
31#include <utils/String8.h>
32
33#include "RpcSocketAddress.h"
34#include "RpcState.h"
35#include "RpcWireFormat.h"
36
37#ifdef __GLIBC__
38extern "C" pid_t gettid();
39#endif
40
41namespace android {
42
43using base::unique_fd;
44
45RpcSession::RpcSession() {
46 LOG_RPC_DETAIL("RpcSession created %p", this);
47
48 mState = std::make_unique<RpcState>();
49}
50RpcSession::~RpcSession() {
51 LOG_RPC_DETAIL("RpcSession destroyed %p", this);
52
53 std::lock_guard<std::mutex> _l(mMutex);
Steven Morelandbb543a82021-05-11 02:31:50 +000054 LOG_ALWAYS_FATAL_IF(mServerConnections.size() != 0,
Steven Morelandbdb53ab2021-05-05 17:57:41 +000055 "Should not be able to destroy a session with servers in use.");
56}
57
58sp<RpcSession> RpcSession::make() {
59 return sp<RpcSession>::make();
60}
61
62bool RpcSession::setupUnixDomainClient(const char* path) {
63 return setupSocketClient(UnixSocketAddress(path));
64}
65
Steven Morelandbdb53ab2021-05-05 17:57:41 +000066bool RpcSession::setupVsockClient(unsigned int cid, unsigned int port) {
67 return setupSocketClient(VsockSocketAddress(cid, port));
68}
69
Steven Morelandbdb53ab2021-05-05 17:57:41 +000070bool RpcSession::setupInetClient(const char* addr, unsigned int port) {
71 auto aiStart = InetSocketAddress::getAddrInfo(addr, port);
72 if (aiStart == nullptr) return false;
73 for (auto ai = aiStart.get(); ai != nullptr; ai = ai->ai_next) {
74 InetSocketAddress socketAddress(ai->ai_addr, ai->ai_addrlen, addr, port);
75 if (setupSocketClient(socketAddress)) return true;
76 }
77 ALOGE("None of the socket address resolved for %s:%u can be added as inet client.", addr, port);
78 return false;
79}
80
81bool RpcSession::addNullDebuggingClient() {
82 unique_fd serverFd(TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY | O_CLOEXEC)));
83
84 if (serverFd == -1) {
85 ALOGE("Could not connect to /dev/null: %s", strerror(errno));
86 return false;
87 }
88
Steven Morelandc8c256b2021-05-11 22:59:09 +000089 addClientConnection(std::move(serverFd));
Steven Morelandbdb53ab2021-05-05 17:57:41 +000090 return true;
91}
92
93sp<IBinder> RpcSession::getRootObject() {
94 ExclusiveConnection connection(sp<RpcSession>::fromExisting(this), ConnectionUse::CLIENT);
95 return state()->getRootObject(connection.fd(), sp<RpcSession>::fromExisting(this));
96}
97
Steven Moreland1be91352021-05-11 22:12:15 +000098status_t RpcSession::getRemoteMaxThreads(size_t* maxThreads) {
Steven Morelandbdb53ab2021-05-05 17:57:41 +000099 ExclusiveConnection connection(sp<RpcSession>::fromExisting(this), ConnectionUse::CLIENT);
100 return state()->getMaxThreads(connection.fd(), sp<RpcSession>::fromExisting(this), maxThreads);
101}
102
Steven Morelandf5174272021-05-25 00:39:28 +0000103status_t RpcSession::transact(const sp<IBinder>& binder, uint32_t code, const Parcel& data,
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000104 Parcel* reply, uint32_t flags) {
105 ExclusiveConnection connection(sp<RpcSession>::fromExisting(this),
106 (flags & IBinder::FLAG_ONEWAY) ? ConnectionUse::CLIENT_ASYNC
107 : ConnectionUse::CLIENT);
Steven Morelandf5174272021-05-25 00:39:28 +0000108 return state()->transact(connection.fd(), binder, code, data,
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000109 sp<RpcSession>::fromExisting(this), reply, flags);
110}
111
112status_t RpcSession::sendDecStrong(const RpcAddress& address) {
113 ExclusiveConnection connection(sp<RpcSession>::fromExisting(this),
114 ConnectionUse::CLIENT_REFCOUNT);
115 return state()->sendDecStrong(connection.fd(), address);
116}
117
Steven Morelande47511f2021-05-20 00:07:41 +0000118std::unique_ptr<RpcSession::FdTrigger> RpcSession::FdTrigger::make() {
119 auto ret = std::make_unique<RpcSession::FdTrigger>();
120 if (!android::base::Pipe(&ret->mRead, &ret->mWrite)) return nullptr;
121 return ret;
122}
123
124void RpcSession::FdTrigger::trigger() {
125 mWrite.reset();
126}
127
Steven Moreland2b4f3802021-05-22 01:46:27 +0000128status_t RpcSession::FdTrigger::triggerablePollRead(base::borrowed_fd fd) {
Steven Moreland4ec3c432021-05-20 00:32:47 +0000129 while (true) {
Steven Morelanddfe3be92021-05-22 00:24:29 +0000130 pollfd pfd[]{{.fd = fd.get(), .events = POLLIN | POLLHUP, .revents = 0},
Steven Moreland4ec3c432021-05-20 00:32:47 +0000131 {.fd = mRead.get(), .events = POLLHUP, .revents = 0}};
132 int ret = TEMP_FAILURE_RETRY(poll(pfd, arraysize(pfd), -1));
133 if (ret < 0) {
Steven Moreland2b4f3802021-05-22 01:46:27 +0000134 return -errno;
Steven Moreland4ec3c432021-05-20 00:32:47 +0000135 }
136 if (ret == 0) {
137 continue;
138 }
139 if (pfd[1].revents & POLLHUP) {
Steven Moreland2b4f3802021-05-22 01:46:27 +0000140 return -ECANCELED;
Steven Moreland4ec3c432021-05-20 00:32:47 +0000141 }
Steven Moreland2b4f3802021-05-22 01:46:27 +0000142 return pfd[0].revents & POLLIN ? OK : DEAD_OBJECT;
Steven Moreland4ec3c432021-05-20 00:32:47 +0000143 }
144}
145
Steven Moreland2b4f3802021-05-22 01:46:27 +0000146status_t RpcSession::FdTrigger::interruptableReadFully(base::borrowed_fd fd, void* data,
147 size_t size) {
Steven Moreland9d11b922021-05-20 01:22:58 +0000148 uint8_t* buffer = reinterpret_cast<uint8_t*>(data);
149 uint8_t* end = buffer + size;
150
Steven Moreland2b4f3802021-05-22 01:46:27 +0000151 status_t status;
152 while ((status = triggerablePollRead(fd)) == OK) {
Steven Moreland9d11b922021-05-20 01:22:58 +0000153 ssize_t readSize = TEMP_FAILURE_RETRY(recv(fd.get(), buffer, end - buffer, MSG_NOSIGNAL));
Steven Moreland2b4f3802021-05-22 01:46:27 +0000154 if (readSize == 0) return DEAD_OBJECT; // EOF
Steven Morelanddfe3be92021-05-22 00:24:29 +0000155
Steven Moreland9d11b922021-05-20 01:22:58 +0000156 if (readSize < 0) {
Steven Moreland2b4f3802021-05-22 01:46:27 +0000157 return -errno;
Steven Moreland9d11b922021-05-20 01:22:58 +0000158 }
159 buffer += readSize;
Steven Moreland2b4f3802021-05-22 01:46:27 +0000160 if (buffer == end) return OK;
Steven Moreland9d11b922021-05-20 01:22:58 +0000161 }
Steven Moreland2b4f3802021-05-22 01:46:27 +0000162 return status;
Steven Moreland9d11b922021-05-20 01:22:58 +0000163}
164
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000165status_t RpcSession::readId() {
166 {
167 std::lock_guard<std::mutex> _l(mMutex);
168 LOG_ALWAYS_FATAL_IF(mForServer != nullptr, "Can only update ID for client.");
169 }
170
171 int32_t id;
172
173 ExclusiveConnection connection(sp<RpcSession>::fromExisting(this), ConnectionUse::CLIENT);
174 status_t status =
175 state()->getSessionId(connection.fd(), sp<RpcSession>::fromExisting(this), &id);
176 if (status != OK) return status;
177
178 LOG_RPC_DETAIL("RpcSession %p has id %d", this, id);
179 mId = id;
180 return OK;
181}
182
Steven Moreland5802c2b2021-05-12 20:13:04 +0000183void RpcSession::preJoin(std::thread thread) {
Steven Morelanda63ff932021-05-12 00:03:15 +0000184 LOG_ALWAYS_FATAL_IF(thread.get_id() != std::this_thread::get_id(), "Must own this thread");
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000185
Steven Morelanda63ff932021-05-12 00:03:15 +0000186 {
187 std::lock_guard<std::mutex> _l(mMutex);
188 mThreads[thread.get_id()] = std::move(thread);
189 }
Steven Moreland5802c2b2021-05-12 20:13:04 +0000190}
Steven Morelanda63ff932021-05-12 00:03:15 +0000191
Steven Moreland5802c2b2021-05-12 20:13:04 +0000192void RpcSession::join(unique_fd client) {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000193 // must be registered to allow arbitrary client code executing commands to
194 // be able to do nested calls (we can't only read from it)
195 sp<RpcConnection> connection = assignServerToThisThread(std::move(client));
196
197 while (true) {
198 status_t error =
199 state()->getAndExecuteCommand(connection->fd, sp<RpcSession>::fromExisting(this));
200
201 if (error != OK) {
Steven Morelandaf4ca712021-05-24 23:22:08 +0000202 LOG_RPC_DETAIL("Binder connection thread closing w/ status %s",
203 statusToString(error).c_str());
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000204 break;
205 }
206 }
207
208 LOG_ALWAYS_FATAL_IF(!removeServerConnection(connection),
209 "bad state: connection object guaranteed to be in list");
Steven Morelanda63ff932021-05-12 00:03:15 +0000210
Steven Morelandee3f4662021-05-22 01:07:33 +0000211 sp<RpcServer> server;
Steven Morelanda63ff932021-05-12 00:03:15 +0000212 {
213 std::lock_guard<std::mutex> _l(mMutex);
214 auto it = mThreads.find(std::this_thread::get_id());
215 LOG_ALWAYS_FATAL_IF(it == mThreads.end());
216 it->second.detach();
217 mThreads.erase(it);
Steven Morelandee3f4662021-05-22 01:07:33 +0000218
219 server = mForServer.promote();
220 }
221
222 if (server != nullptr) {
223 server->onSessionThreadEnding(sp<RpcSession>::fromExisting(this));
Steven Morelanda63ff932021-05-12 00:03:15 +0000224 }
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000225}
226
Steven Morelandee78e762021-05-05 21:12:51 +0000227void RpcSession::terminateLocked() {
228 // TODO(b/185167543):
229 // - kindly notify other side of the connection of termination (can't be
230 // locked)
231 // - prevent new client/servers from being added
232 // - stop all threads which are currently reading/writing
233 // - terminate RpcState?
234
235 if (mTerminated) return;
236
237 sp<RpcServer> server = mForServer.promote();
238 if (server) {
239 server->onSessionTerminating(sp<RpcSession>::fromExisting(this));
240 }
241}
242
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000243wp<RpcServer> RpcSession::server() {
244 return mForServer;
245}
246
247bool RpcSession::setupSocketClient(const RpcSocketAddress& addr) {
248 {
249 std::lock_guard<std::mutex> _l(mMutex);
Steven Morelandbb543a82021-05-11 02:31:50 +0000250 LOG_ALWAYS_FATAL_IF(mClientConnections.size() != 0,
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000251 "Must only setup session once, but already has %zu clients",
Steven Morelandbb543a82021-05-11 02:31:50 +0000252 mClientConnections.size());
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000253 }
254
255 if (!setupOneSocketClient(addr, RPC_SESSION_ID_NEW)) return false;
256
257 // TODO(b/185167543): we should add additional sessions dynamically
258 // instead of all at once.
259 // TODO(b/186470974): first risk of blocking
260 size_t numThreadsAvailable;
Steven Moreland1be91352021-05-11 22:12:15 +0000261 if (status_t status = getRemoteMaxThreads(&numThreadsAvailable); status != OK) {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000262 ALOGE("Could not get max threads after initial session to %s: %s", addr.toString().c_str(),
263 statusToString(status).c_str());
264 return false;
265 }
266
267 if (status_t status = readId(); status != OK) {
268 ALOGE("Could not get session id after initial session to %s; %s", addr.toString().c_str(),
269 statusToString(status).c_str());
270 return false;
271 }
272
273 // we've already setup one client
274 for (size_t i = 0; i + 1 < numThreadsAvailable; i++) {
Steven Moreland76d2c1f2021-05-05 20:28:58 +0000275 // TODO(b/185167543): shutdown existing connections?
276 if (!setupOneSocketClient(addr, mId.value())) return false;
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000277 }
278
279 return true;
280}
281
282bool RpcSession::setupOneSocketClient(const RpcSocketAddress& addr, int32_t id) {
Steven Moreland76d2c1f2021-05-05 20:28:58 +0000283 for (size_t tries = 0; tries < 5; tries++) {
284 if (tries > 0) usleep(10000);
285
286 unique_fd serverFd(
287 TEMP_FAILURE_RETRY(socket(addr.addr()->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)));
288 if (serverFd == -1) {
289 int savedErrno = errno;
290 ALOGE("Could not create socket at %s: %s", addr.toString().c_str(),
291 strerror(savedErrno));
292 return false;
293 }
294
295 if (0 != TEMP_FAILURE_RETRY(connect(serverFd.get(), addr.addr(), addr.addrSize()))) {
296 if (errno == ECONNRESET) {
297 ALOGW("Connection reset on %s", addr.toString().c_str());
298 continue;
299 }
300 int savedErrno = errno;
301 ALOGE("Could not connect socket at %s: %s", addr.toString().c_str(),
302 strerror(savedErrno));
303 return false;
304 }
305
306 if (sizeof(id) != TEMP_FAILURE_RETRY(write(serverFd.get(), &id, sizeof(id)))) {
307 int savedErrno = errno;
308 ALOGE("Could not write id to socket at %s: %s", addr.toString().c_str(),
309 strerror(savedErrno));
310 return false;
311 }
312
313 LOG_RPC_DETAIL("Socket at %s client with fd %d", addr.toString().c_str(), serverFd.get());
314
Steven Morelandc8c256b2021-05-11 22:59:09 +0000315 addClientConnection(std::move(serverFd));
Steven Moreland76d2c1f2021-05-05 20:28:58 +0000316 return true;
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000317 }
318
Steven Moreland76d2c1f2021-05-05 20:28:58 +0000319 ALOGE("Ran out of retries to connect to %s", addr.toString().c_str());
320 return false;
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000321}
322
Steven Morelandc8c256b2021-05-11 22:59:09 +0000323void RpcSession::addClientConnection(unique_fd fd) {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000324 std::lock_guard<std::mutex> _l(mMutex);
Steven Morelandee3f4662021-05-22 01:07:33 +0000325
326 if (mShutdownTrigger == nullptr) {
327 mShutdownTrigger = FdTrigger::make();
328 }
329
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000330 sp<RpcConnection> session = sp<RpcConnection>::make();
331 session->fd = std::move(fd);
Steven Morelandbb543a82021-05-11 02:31:50 +0000332 mClientConnections.push_back(session);
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000333}
334
Steven Morelandee3f4662021-05-22 01:07:33 +0000335void RpcSession::setForServer(const wp<RpcServer>& server, int32_t sessionId,
336 const std::shared_ptr<FdTrigger>& shutdownTrigger) {
337 LOG_ALWAYS_FATAL_IF(mForServer.unsafe_get() != nullptr);
338 LOG_ALWAYS_FATAL_IF(mShutdownTrigger != nullptr);
339 LOG_ALWAYS_FATAL_IF(shutdownTrigger == nullptr);
340
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000341 mId = sessionId;
342 mForServer = server;
Steven Morelandee3f4662021-05-22 01:07:33 +0000343 mShutdownTrigger = shutdownTrigger;
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000344}
345
346sp<RpcSession::RpcConnection> RpcSession::assignServerToThisThread(unique_fd fd) {
347 std::lock_guard<std::mutex> _l(mMutex);
348 sp<RpcConnection> session = sp<RpcConnection>::make();
349 session->fd = std::move(fd);
350 session->exclusiveTid = gettid();
Steven Morelandbb543a82021-05-11 02:31:50 +0000351 mServerConnections.push_back(session);
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000352
353 return session;
354}
355
356bool RpcSession::removeServerConnection(const sp<RpcConnection>& connection) {
357 std::lock_guard<std::mutex> _l(mMutex);
Steven Morelandbb543a82021-05-11 02:31:50 +0000358 if (auto it = std::find(mServerConnections.begin(), mServerConnections.end(), connection);
359 it != mServerConnections.end()) {
360 mServerConnections.erase(it);
361 if (mServerConnections.size() == 0) {
Steven Morelandee78e762021-05-05 21:12:51 +0000362 terminateLocked();
363 }
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000364 return true;
365 }
366 return false;
367}
368
369RpcSession::ExclusiveConnection::ExclusiveConnection(const sp<RpcSession>& session,
370 ConnectionUse use)
371 : mSession(session) {
372 pid_t tid = gettid();
373 std::unique_lock<std::mutex> _l(mSession->mMutex);
374
375 mSession->mWaitingThreads++;
376 while (true) {
377 sp<RpcConnection> exclusive;
378 sp<RpcConnection> available;
379
380 // CHECK FOR DEDICATED CLIENT SOCKET
381 //
382 // A server/looper should always use a dedicated session if available
Steven Morelandbb543a82021-05-11 02:31:50 +0000383 findConnection(tid, &exclusive, &available, mSession->mClientConnections,
384 mSession->mClientConnectionsOffset);
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000385
386 // WARNING: this assumes a server cannot request its client to send
Steven Morelandbb543a82021-05-11 02:31:50 +0000387 // a transaction, as mServerConnections is excluded below.
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000388 //
389 // Imagine we have more than one thread in play, and a single thread
390 // sends a synchronous, then an asynchronous command. Imagine the
391 // asynchronous command is sent on the first client connection. Then, if
392 // we naively send a synchronous command to that same connection, the
393 // thread on the far side might be busy processing the asynchronous
394 // command. So, we move to considering the second available thread
395 // for subsequent calls.
396 if (use == ConnectionUse::CLIENT_ASYNC && (exclusive != nullptr || available != nullptr)) {
Steven Morelandbb543a82021-05-11 02:31:50 +0000397 mSession->mClientConnectionsOffset =
398 (mSession->mClientConnectionsOffset + 1) % mSession->mClientConnections.size();
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000399 }
400
401 // USE SERVING SOCKET (for nested transaction)
402 //
403 // asynchronous calls cannot be nested
404 if (use != ConnectionUse::CLIENT_ASYNC) {
405 // server connections are always assigned to a thread
Steven Morelandbb543a82021-05-11 02:31:50 +0000406 findConnection(tid, &exclusive, nullptr /*available*/, mSession->mServerConnections,
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000407 0 /* index hint */);
408 }
409
410 // if our thread is already using a session, prioritize using that
411 if (exclusive != nullptr) {
412 mConnection = exclusive;
413 mReentrant = true;
414 break;
415 } else if (available != nullptr) {
416 mConnection = available;
417 mConnection->exclusiveTid = tid;
418 break;
419 }
420
421 // in regular binder, this would usually be a deadlock :)
Steven Morelandbb543a82021-05-11 02:31:50 +0000422 LOG_ALWAYS_FATAL_IF(mSession->mClientConnections.size() == 0,
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000423 "Not a client of any session. You must create a session to an "
424 "RPC server to make any non-nested (e.g. oneway or on another thread) "
425 "calls.");
426
427 LOG_RPC_DETAIL("No available session (have %zu clients and %zu servers). Waiting...",
Steven Morelandbb543a82021-05-11 02:31:50 +0000428 mSession->mClientConnections.size(), mSession->mServerConnections.size());
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000429 mSession->mAvailableConnectionCv.wait(_l);
430 }
431 mSession->mWaitingThreads--;
432}
433
434void RpcSession::ExclusiveConnection::findConnection(pid_t tid, sp<RpcConnection>* exclusive,
435 sp<RpcConnection>* available,
436 std::vector<sp<RpcConnection>>& sockets,
437 size_t socketsIndexHint) {
438 LOG_ALWAYS_FATAL_IF(sockets.size() > 0 && socketsIndexHint >= sockets.size(),
439 "Bad index %zu >= %zu", socketsIndexHint, sockets.size());
440
441 if (*exclusive != nullptr) return; // consistent with break below
442
443 for (size_t i = 0; i < sockets.size(); i++) {
444 sp<RpcConnection>& socket = sockets[(i + socketsIndexHint) % sockets.size()];
445
446 // take first available session (intuition = caching)
447 if (available && *available == nullptr && socket->exclusiveTid == std::nullopt) {
448 *available = socket;
449 continue;
450 }
451
452 // though, prefer to take session which is already inuse by this thread
453 // (nested transactions)
454 if (exclusive && socket->exclusiveTid == tid) {
455 *exclusive = socket;
456 break; // consistent with return above
457 }
458 }
459}
460
461RpcSession::ExclusiveConnection::~ExclusiveConnection() {
462 // reentrant use of a session means something less deep in the call stack
463 // is using this fd, and it retains the right to it. So, we don't give up
464 // exclusive ownership, and no thread is freed.
465 if (!mReentrant) {
466 std::unique_lock<std::mutex> _l(mSession->mMutex);
467 mConnection->exclusiveTid = std::nullopt;
468 if (mSession->mWaitingThreads > 0) {
469 _l.unlock();
470 mSession->mAvailableConnectionCv.notify_one();
471 }
472 }
473}
474
475} // namespace android