Transport threadpool configuration.
Servers can specify the number of threads they'd like to
have for handling incoming RPC calls, as well as whether
they'd like to join the threadpool themselves, by calling:
configureRpcThreadpool(numThreads, true /* callerWillJoin */);
This method *must* be called before interacting with any
HIDL services, including the servicemanager through
IFoo::getService / IFoo.registerAsService().
If the server indicated it wanted to join, it should do so
as soon as it can with:
joinRpcThreadpool();
This allows a server full flexibility:
- Without any of these calls, a threadpool of size 1 will be
started, and the main thread won't be a part of it.
- If the server wants a single-threaded RPC pool with its own
main thread for handling incoming RPC transactions, it can call
configureRpcThreadpool(1, true) followed by joinRpcThreadpool().
- If the server wants a multi-threaded RPC pool, it can call
configureRpcThreadpool(5, join) followed by joinRpcThreadpool()
if join was set to true.
Bug: 31226656
Test: mma, hidl_test
Change-Id: I9a3c68ebbe34ea9f14cdae48ca9908d05012c3f2
diff --git a/transport/include/hidl/LegacySupport.h b/transport/include/hidl/LegacySupport.h
index 2ff1785..8fd1795 100644
--- a/transport/include/hidl/LegacySupport.h
+++ b/transport/include/hidl/LegacySupport.h
@@ -14,10 +14,9 @@
* limitations under the License.
*/
+#include <hidl/HidlTransportSupport.h>
+#include <sys/wait.h>
#include <utils/Log.h>
-
-#include <hwbinder/IPCThreadState.h>
-#include <hwbinder/ProcessState.h>
#include <utils/Errors.h>
#include <utils/StrongPointer.h>
@@ -53,27 +52,16 @@
}
/**
- * Launches the RPC threadpool. This method never returns.
- *
- * Return value is exit status.
- */
-inline int launchRpcServer(size_t maxThreads) {
- ProcessState::self()->setThreadPoolMaxThreadCount(maxThreads);
- ProcessState::self()->startThreadPool();
- IPCThreadState::self()->joinThreadPool();
-
- return 0;
-}
-
-/**
* Creates default passthrough service implementation. This method never returns.
*
* Return value is exit status.
*/
template<class Interface>
-int defaultPassthroughServiceImplementation(std::string name) {
+int defaultPassthroughServiceImplementation(std::string name, size_t maxThreads = 1) {
+ configureRpcThreadpool(maxThreads, true);
registerPassthroughServiceImplementation<Interface>(name);
- return launchRpcServer(0);
+ joinRpcThreadpool();
+ return 0;
}
} // namespace hardware