Change default hwbinder threadpool behavior.
In order to allow single-threaded server operation,
we want to allow the creation of processes with just
a single thread handling incoming binder transactions.
This is somewhat tricky, because registering an interface
by itself will start a threadpool (in auto-generated code).
The only way to really prevent this is to allow clients/servers
to configure their desired threadpool configuration in advance.
To that end, ProcessState::setThreadPoolConfiguration() tells
libhwbinder how many RPC threads the caller wants in its process,
and whether the caller wants to join the threadpool itself. If it
does, it must follow up with a call to IPCThreadState::joinThreadPool()
later.
The main change in behavior is that by default, we now only spawn
a single hwbinder thread, and don't allow the kernel to create any
additional threads beyond that.
Bug: 31226656
Test: mma, hidl_test
Change-Id: Id5caa2702e6b2d7fb266801ee0aad2523107e8dd
diff --git a/include/hwbinder/ProcessState.h b/include/hwbinder/ProcessState.h
index 11e5123..2ed1304 100644
--- a/include/hwbinder/ProcessState.h
+++ b/include/hwbinder/ProcessState.h
@@ -39,18 +39,18 @@
void setContextObject(const sp<IBinder>& object);
sp<IBinder> getContextObject(const sp<IBinder>& caller);
-
+
void setContextObject(const sp<IBinder>& object,
const String16& name);
sp<IBinder> getContextObject(const String16& name,
const sp<IBinder>& caller);
void startThreadPool();
-
+
typedef bool (*context_check_func)(const String16& name,
const sp<IBinder>& caller,
void* userData);
-
+
bool isContextManager(void) const;
bool becomeContextManager(
context_check_func checkFunc,
@@ -61,13 +61,13 @@
void expungeHandle(int32_t handle, IBinder* binder);
void spawnPooledThread(bool isMain);
-
- status_t setThreadPoolMaxThreadCount(size_t maxThreads);
+
+ status_t setThreadPoolConfiguration(size_t maxThreads, bool callerJoinsPool);
void giveThreadPoolName();
private:
friend class IPCThreadState;
-
+
ProcessState();
~ProcessState();
@@ -109,9 +109,10 @@
String8 mRootDir;
bool mThreadPoolStarted;
+ bool mSpawnThreadOnStart;
volatile int32_t mThreadPoolSeq;
};
-
+
}; // namespace hardware
}; // namespace android