Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4354f713 authored by Devin Moore's avatar Devin Moore
Browse files

binder: Add an API to check if the threadpool has been started

Libraries that require the threadpool can check this to make sure the
threadpool has been started before it is needed.

Test: atest binderLibTest
Bug: 261652496
Change-Id: I7505319f162e2789dcc3c41bf1f7535c5c1bb9d9
parent 9c0835a8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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[] = {
+5 −0
Original line number Diff line number Diff line
@@ -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,
+7 −0
Original line number Diff line number Diff line
@@ -42,6 +42,13 @@ void ABinderProcess_startThreadPool();
 * function should be responsible for configuring the threadpool for the entire application.
 */
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.
+1 −0
Original line number Diff line number Diff line
@@ -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
+3 −0
Original line number Diff line number Diff line
@@ -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();
}
Loading