Avoid waiting from polling binder threads
It's not enough to test whether we're the only looper thread. In the
case of a polling binder implementation, there is still only one thread
able to handle callbacks. That thread will also have to fall back to
the inefficient check-and-recheck method rather than waiting.
As such, ask whether we're the sole binder thread instead.
Bug: 71625413
Test: start a polling hwbinder service (e.g. healthd@2.0/backup) before
its dependency; doesn't hang.
Change-Id: Ie2ae4f5705aba17f20227f1e1a58341d4da13fe1
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index ef86f99..4bdeb6e 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -485,8 +485,7 @@
// that thread, it will block forever because we hung up the one and only
// binder thread on a condition variable that can only be notified by an
// incoming binder call.
- if (ProcessState::self()->getMaxThreads() <= 1 &&
- IPCThreadState::self()->isLooperThread()) {
+ if (IPCThreadState::self()->isOnlyBinderThread()) {
LOG(WARNING) << "Can't efficiently wait for " << mInterfaceName << "/"
<< mInstanceName << ", because we are called from "
<< "the only binder thread in this process.";