diff options
author | 2021-01-19 17:40:23 +0000 | |
---|---|---|
committer | 2021-01-19 17:40:23 +0000 | |
commit | ff30b34cd24b23c8eb899ace1daf7a33db86a775 (patch) | |
tree | 13ffb7f1f5b51a05da5e4b3bd4588c05560b4cfc /libs/binder/IPCThreadState.cpp | |
parent | b86f892039f13f689ea8df485cc5ac908999afe2 (diff) | |
parent | c648a765dc0e3008db62a368df3ea7592d4c2452 (diff) |
Merge "libbinder - avoid pthread_cond_broadcast per call"
Diffstat (limited to 'libs/binder/IPCThreadState.cpp')
-rw-r--r-- | libs/binder/IPCThreadState.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index 2eee2c40a3..b038feb878 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -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; } - pthread_cond_broadcast(&mProcess->mThreadCountDecrement); + + // 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); } |