diff options
author | Martijn Coenen <maco@google.com> | 2016-11-22 14:53:47 +0100 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2016-12-30 10:29:51 +0100 |
commit | e76c7a27eeb3763a2185c1502fd4572df1513b9a (patch) | |
tree | ee99b4de96ad818427deb42c765f51fb8263fe48 /transport/memory | |
parent | 4be08f0b1dedda6659332141c76f5928f74c9f7e (diff) | |
download | libhidl-e76c7a27eeb3763a2185c1502fd4572df1513b9a.tar.gz |
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
Diffstat (limited to 'transport/memory')
-rw-r--r-- | transport/memory/1.0/default/service.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/transport/memory/1.0/default/service.cpp b/transport/memory/1.0/default/service.cpp index 8ea8b8a..0302e51 100644 --- a/transport/memory/1.0/default/service.cpp +++ b/transport/memory/1.0/default/service.cpp @@ -4,17 +4,18 @@ #include <android-base/logging.h> #include <android/hidl/memory/1.0/IAllocator.h> -#include <hwbinder/IPCThreadState.h> -#include <hwbinder/ProcessState.h> +#include <hidl/HidlTransportSupport.h> -using android::hardware::IPCThreadState; -using android::hardware::ProcessState; +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; using android::hidl::memory::V1_0::IAllocator; using android::hidl::memory::V1_0::implementation::AshmemAllocator; using android::sp; using android::status_t; int main() { + configureRpcThreadpool(1, true /* callerWillJoin */); + sp<IAllocator> allocator = new AshmemAllocator(); status_t status = allocator->registerAsService("ashmem"); @@ -23,9 +24,7 @@ int main() { LOG(FATAL) << "Unable to register allocator service: " << status; } - ProcessState::self()->setThreadPoolMaxThreadCount(0); - ProcessState::self()->startThreadPool(); - IPCThreadState::self()->joinThreadPool(); + joinRpcThreadpool(); return -1; } |