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

Commit ff30b34c authored by Steven Moreland's avatar Steven Moreland Committed by Gerrit Code Review
Browse files

Merge "libbinder - avoid pthread_cond_broadcast per call"

parents b86f8920 c648a765
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -489,12 +489,14 @@ void IPCThreadState::flushCommands()
void IPCThreadState::blockUntilThreadAvailable()
{
    pthread_mutex_lock(&mProcess->mThreadCountLock);
    mProcess->mWaitingForThreads++;
    while (mProcess->mExecutingThreadsCount >= mProcess->mMaxThreads) {
        ALOGW("Waiting for thread to be free. mExecutingThreadsCount=%lu mMaxThreads=%lu\n",
                static_cast<unsigned long>(mProcess->mExecutingThreadsCount),
                static_cast<unsigned long>(mProcess->mMaxThreads));
        pthread_cond_wait(&mProcess->mThreadCountDecrement, &mProcess->mThreadCountLock);
    }
    mProcess->mWaitingForThreads--;
    pthread_mutex_unlock(&mProcess->mThreadCountLock);
}

@@ -534,7 +536,12 @@ status_t IPCThreadState::getAndExecuteCommand()
            }
            mProcess->mStarvationStartTimeMs = 0;
        }

        // Cond broadcast can be expensive, so don't send it every time a binder
        // call is processed. b/168806193
        if (mProcess->mWaitingForThreads > 0) {
            pthread_cond_broadcast(&mProcess->mThreadCountDecrement);
        }
        pthread_mutex_unlock(&mProcess->mThreadCountLock);
    }

+1 −0
Original line number Diff line number Diff line
@@ -399,6 +399,7 @@ ProcessState::ProcessState(const char *driver)
    , mThreadCountLock(PTHREAD_MUTEX_INITIALIZER)
    , mThreadCountDecrement(PTHREAD_COND_INITIALIZER)
    , mExecutingThreadsCount(0)
    , mWaitingForThreads(0)
    , mMaxThreads(DEFAULT_MAX_BINDER_THREADS)
    , mStarvationStartTimeMs(0)
    , mThreadPoolStarted(false)
+4 −1
Original line number Diff line number Diff line
@@ -107,11 +107,14 @@ private:
            int                 mDriverFD;
            void*               mVMStart;

            // Protects thread count variable below.
            // Protects thread count and wait variables below.
            pthread_mutex_t     mThreadCountLock;
            // Broadcast whenever mWaitingForThreads > 0
            pthread_cond_t      mThreadCountDecrement;
            // Number of binder threads current executing a command.
            size_t              mExecutingThreadsCount;
            // Number of threads calling IPCThreadState::blockUntilThreadAvailable()
            size_t              mWaitingForThreads;
            // Maximum number for binder threads allowed for this process.
            size_t              mMaxThreads;
            // Time when thread pool was emptied