diff options
| author | 2022-12-09 20:10:14 +0000 | |
|---|---|---|
| committer | 2022-12-09 20:10:14 +0000 | |
| commit | 1661658b8b793eeb000732eae8e9e2bf82b9600a (patch) | |
| tree | a0f2d388c7ebbf85994d7b48063409cd927c3ff2 | |
| parent | a89952b69befde0d8cc3f08b1102f5006bc623b4 (diff) | |
| parent | 13ba5335585d7aa7dc774667d2c0992db7de819c (diff) | |
Merge "binder: Add an API to check if the threadpool has been started" am: 13ba533558
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2334882
Change-Id: I87e5ccf342860456bafc366d9412c9881a2f1fe2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | libs/binder/ProcessState.cpp | 4 | ||||
| -rw-r--r-- | libs/binder/include/binder/ProcessState.h | 5 | ||||
| -rw-r--r-- | libs/binder/ndk/include_platform/android/binder_process.h | 7 | ||||
| -rw-r--r-- | libs/binder/ndk/libbinder_ndk.map.txt | 1 | ||||
| -rw-r--r-- | libs/binder/ndk/process.cpp | 3 | ||||
| -rw-r--r-- | libs/binder/tests/binderLibTest.cpp | 13 |
6 files changed, 33 insertions, 0 deletions
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index 1f311acb20..254dda81a6 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -439,6 +439,10 @@ size_t ProcessState::getThreadPoolMaxTotalThreadCount() const { return mCurrentThreads; } +bool ProcessState::isThreadPoolStarted() const { + return mThreadPoolStarted; +} + #define DRIVER_FEATURES_PATH "/dev/binderfs/features/" bool ProcessState::isDriverFeatureEnabled(const DriverFeature feature) { static const char* const names[] = { diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h index 87eee3d0f2..bad8cb1bed 100644 --- a/libs/binder/include/binder/ProcessState.h +++ b/libs/binder/include/binder/ProcessState.h @@ -97,6 +97,11 @@ public: */ size_t getThreadPoolMaxTotalThreadCount() const; + /** + * Check to see if the thread pool has started. + */ + bool isThreadPoolStarted() const; + enum class DriverFeature { ONEWAY_SPAM_DETECTION, EXTENDED_ERROR, diff --git a/libs/binder/ndk/include_platform/android/binder_process.h b/libs/binder/ndk/include_platform/android/binder_process.h index 89231295dd..ffcad559f6 100644 --- a/libs/binder/ndk/include_platform/android/binder_process.h +++ b/libs/binder/ndk/include_platform/android/binder_process.h @@ -43,6 +43,13 @@ void ABinderProcess_startThreadPool(); */ bool ABinderProcess_setThreadPoolMaxThreadCount(uint32_t numThreads); /** + * Check if the threadpool has already been started. + * This tells whether someone in the process has called ABinderProcess_startThreadPool. Usually, + * you should use this in a library to abort if the threadpool is not started. + * Programs should configure binder threadpools once at the beginning. + */ +bool ABinderProcess_isThreadPoolStarted(); +/** * This adds the current thread to the threadpool. This may cause the threadpool to exceed the * maximum size. * diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt index 5c7005ceb7..54e46287a9 100644 --- a/libs/binder/ndk/libbinder_ndk.map.txt +++ b/libs/binder/ndk/libbinder_ndk.map.txt @@ -154,6 +154,7 @@ LIBBINDER_NDK33 { # introduced=33 LIBBINDER_NDK34 { # introduced=UpsideDownCake global: + ABinderProcess_isThreadPoolStarted; # systemapi llndk AServiceManager_getUpdatableApexName; # systemapi AServiceManager_registerForServiceNotifications; # systemapi llndk AServiceManager_NotificationRegistration_delete; # systemapi llndk diff --git a/libs/binder/ndk/process.cpp b/libs/binder/ndk/process.cpp index ac582a412e..bc6610e3b9 100644 --- a/libs/binder/ndk/process.cpp +++ b/libs/binder/ndk/process.cpp @@ -31,6 +31,9 @@ void ABinderProcess_startThreadPool() { bool ABinderProcess_setThreadPoolMaxThreadCount(uint32_t numThreads) { return ProcessState::self()->setThreadPoolMaxThreadCount(numThreads) == 0; } +bool ABinderProcess_isThreadPoolStarted() { + return ProcessState::self()->isThreadPoolStarted(); +} void ABinderProcess_joinThreadPool() { IPCThreadState::self()->joinThreadPool(); } diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp index 25b524fcf2..f7498c497b 100644 --- a/libs/binder/tests/binderLibTest.cpp +++ b/libs/binder/tests/binderLibTest.cpp @@ -120,6 +120,7 @@ enum BinderLibTestTranscationCode { BINDER_LIB_TEST_CAN_GET_SID, BINDER_LIB_TEST_GET_MAX_THREAD_COUNT, BINDER_LIB_TEST_SET_MAX_THREAD_COUNT, + BINDER_LIB_TEST_IS_THREADPOOL_STARTED, BINDER_LIB_TEST_LOCK_UNLOCK, BINDER_LIB_TEST_PROCESS_LOCK, BINDER_LIB_TEST_UNLOCK_AFTER_MS, @@ -1383,6 +1384,14 @@ TEST_F(BinderLibTest, ThreadPoolAvailableThreads) { EXPECT_EQ(replyi, kKernelThreads + 1); } +TEST_F(BinderLibTest, ThreadPoolStarted) { + Parcel data, reply; + sp<IBinder> server = addServer(); + ASSERT_TRUE(server != nullptr); + EXPECT_THAT(server->transact(BINDER_LIB_TEST_IS_THREADPOOL_STARTED, data, &reply), NO_ERROR); + EXPECT_TRUE(reply.readBool()); +} + size_t epochMillis() { using std::chrono::duration_cast; using std::chrono::milliseconds; @@ -1849,6 +1858,10 @@ public: reply->writeInt32(ProcessState::self()->getThreadPoolMaxTotalThreadCount()); return NO_ERROR; } + case BINDER_LIB_TEST_IS_THREADPOOL_STARTED: { + reply->writeBool(ProcessState::self()->isThreadPoolStarted()); + return NO_ERROR; + } case BINDER_LIB_TEST_PROCESS_LOCK: { m_blockMutex.lock(); return NO_ERROR; |