diff options
author | Wale Ogunwale <ogunwale@google.com> | 2015-04-13 16:16:10 -0700 |
---|---|---|
committer | Wale Ogunwale <ogunwale@google.com> | 2015-04-14 13:17:25 -0700 |
commit | 376b822728c582a9deb26ce339deb5204ae4d22e (patch) | |
tree | 4da29f139d56f197760860b9e98523396e4bcc7e /libs/binder/IPCThreadState.cpp | |
parent | e88e3669632972fedc85b23a2b108f56222c6eb4 (diff) | |
download | frameworks_native-376b822728c582a9deb26ce339deb5204ae4d22e.zip frameworks_native-376b822728c582a9deb26ce339deb5204ae4d22e.tar.gz frameworks_native-376b822728c582a9deb26ce339deb5204ae4d22e.tar.bz2 |
Added IPCThreadState::blockUntilThreadAvailable() method.
Will be used by the system_server watchdog to monitor the
availability of binder threads in the process to handle
incoming IPC requests.
Bug: 19297165
Change-Id: I39175f3869ad14da5620fddb47f454e6e4ee2b25
Diffstat (limited to 'libs/binder/IPCThreadState.cpp')
-rw-r--r-- | libs/binder/IPCThreadState.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index 9f68aa8..2baf474 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -399,6 +399,17 @@ void IPCThreadState::flushCommands() talkWithDriver(false); } +void IPCThreadState::blockUntilThreadAvailable() +{ + pthread_mutex_lock(&mProcess->mThreadCountLock); + while (mProcess->mExecutingThreadsCount >= mProcess->mMaxThreads) { + ALOGW("Waiting for thread to be free. mExecutingThreadsCount=%i mMaxThreads=%i\n", + mProcess->mExecutingThreadsCount, mProcess->mMaxThreads); + pthread_cond_wait(&mProcess->mThreadCountDecrement, &mProcess->mThreadCountLock); + } + pthread_mutex_unlock(&mProcess->mThreadCountLock); +} + status_t IPCThreadState::getAndExecuteCommand() { status_t result; @@ -414,8 +425,17 @@ status_t IPCThreadState::getAndExecuteCommand() << getReturnString(cmd) << endl; } + pthread_mutex_lock(&mProcess->mThreadCountLock); + mProcess->mExecutingThreadsCount++; + pthread_mutex_unlock(&mProcess->mThreadCountLock); + result = executeCommand(cmd); + pthread_mutex_lock(&mProcess->mThreadCountLock); + mProcess->mExecutingThreadsCount--; + pthread_cond_broadcast(&mProcess->mThreadCountDecrement); + pthread_mutex_unlock(&mProcess->mThreadCountLock); + // After executing the command, ensure that the thread is returned to the // foreground cgroup before rejoining the pool. The driver takes care of // restoring the priority, but doesn't do anything with cgroups so we |