Skip to content

Commit 38a4ab9

Browse files
Steven MorelandGerrit Code Review
authored andcommitted
Merge "libbinder: log when threads requested, not started" into main
2 parents 99871bf + c86333d commit 38a4ab9

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

libs/binder/IPCThreadState.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ void IPCThreadState::joinThreadPool(bool isMain)
775775
{
776776
LOG_THREADPOOL("**** THREAD %p (PID %d) IS JOINING THE THREAD POOL\n", (void*)pthread_self(),
777777
getpid());
778+
mProcess->checkExpectingThreadPoolStart();
778779
mProcess->mCurrentThreads++;
779780
mOut.writeInt32(isMain ? BC_ENTER_LOOPER : BC_REGISTER_LOOPER);
780781

libs/binder/ProcessState.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,21 @@ bool ProcessState::isThreadPoolStarted() const {
501501
return mThreadPoolStarted;
502502
}
503503

504+
void ProcessState::checkExpectingThreadPoolStart() const {
505+
if (mThreadPoolStarted) return;
506+
507+
// this is also racey, but you should setup the threadpool in the main thread. If that is an
508+
// issue, we can check if we are the process leader, but haven't seen the issue in practice.
509+
size_t requestedThreads = mMaxThreads.load();
510+
511+
// if it's manually set to the default, we do ignore it here...
512+
if (requestedThreads == DEFAULT_MAX_BINDER_THREADS) return;
513+
if (requestedThreads == 0) return;
514+
515+
ALOGW("Thread pool configuration of size %zu requested, but startThreadPool was not called.",
516+
requestedThreads);
517+
}
518+
504519
#define DRIVER_FEATURES_PATH "/dev/binderfs/features/"
505520
bool ProcessState::isDriverFeatureEnabled(const DriverFeature feature) {
506521
// Use static variable to cache the results.

libs/binder/include/binder/ProcessState.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class ProcessState : public virtual RefBase {
141141
private:
142142
static sp<ProcessState> init(const char* defaultDriver, bool requireDefault);
143143

144+
void checkExpectingThreadPoolStart() const;
145+
144146
static void onFork();
145147
static void parentPostFork();
146148
static void childPostFork();

0 commit comments

Comments
 (0)