Enforce configureRpcThreadpool before join.
This pattern:
/* BAD */ int main() {
/* BAD */ sp<IFoo> foo = new IFoo();
/* BAD */ ... = foo->registerAsService();
/* BAD */ ...
/* BAD */ joinRpcThreadpool();
/* BAD */ return 1;
/* BAD */ }
Causes two hwbinder threads to be created because one is
created when registerAsService is called and another is
created by the main thread joining the threadpool.
Rather than allow accidentally creating a second thread,
fail hard on this error. Creating a second thread when it
is not explicitly requested.
Instead this call should be added before registerAsService:
configureRpcThreadpool(K, true /* willJoin */);
Where 'K' is the number of desired threads ('1' for
single-threaded services, '2' if two threads are actually
desired, and so on).
Fixes: 80102279
Test: Boot multiple Pixels
Change-Id: Ib3437f023ca0642649bcd85c1976d7cc42d2c336
diff --git a/transport/HidlBinderSupport.cpp b/transport/HidlBinderSupport.cpp
index 4a24a3e..f6c7bff 100644
--- a/transport/HidlBinderSupport.cpp
+++ b/transport/HidlBinderSupport.cpp
@@ -207,10 +207,8 @@
}
void joinBinderRpcThreadpool() {
- if (!gThreadPoolConfigured) {
- ALOGE("HIDL joinRpcThreadpool without calling configureRpcThreadPool.");
- }
-
+ LOG_ALWAYS_FATAL_IF(!gThreadPoolConfigured,
+ "HIDL joinRpcThreadpool without calling configureRpcThreadPool.");
IPCThreadState::self()->joinThreadPool();
}
@@ -218,9 +216,7 @@
int fd;
int err = IPCThreadState::self()->setupPolling(&fd);
- if (err != OK) {
- ALOGE("Failed to setup binder polling: %d (%s)", err, strerror(err));
- }
+ LOG_ALWAYS_FATAL_IF(err != OK, "Failed to setup binder polling: %d (%s)", err, strerror(err));
return err == OK ? fd : -1;
}