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

Commit b763b149 authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: get threadpool count locked

These variables might be changed by another thread.

Bug: 233226955
Test: atest binderLibTest
Change-Id: I384f309ed1cc7c062ccc5eaab9f6f6a57142cf7f
parent 29d54149
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <binder/ProcessState.h>

#include <android-base/result.h>
#include <android-base/scopeguard.h>
#include <android-base/strings.h>
#include <binder/BpBinder.h>
#include <binder/IPCThreadState.h>
@@ -420,6 +421,9 @@ status_t ProcessState::setThreadPoolMaxThreadCount(size_t maxThreads) {
}

size_t ProcessState::getThreadPoolMaxTotalThreadCount() const {
    pthread_mutex_lock(&mThreadCountLock);
    base::ScopeGuard detachGuard = [&]() { pthread_mutex_unlock(&mThreadCountLock); };

    // may actually be one more than this, if join is called
    if (mThreadPoolStarted) {
        return mCurrentThreads < mKernelStartedThreads
+1 −1
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ private:
    void* mVMStart;

    // Protects thread count and wait variables below.
    pthread_mutex_t mThreadCountLock;
    mutable pthread_mutex_t mThreadCountLock;
    // Broadcast whenever mWaitingForThreads > 0
    pthread_cond_t mThreadCountDecrement;
    // Number of binder threads current executing a command.