1164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian/* 2164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * Copyright (C) 2005 The Android Open Source Project 3164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * 4164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * you may not use this file except in compliance with the License. 6164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * You may obtain a copy of the License at 7164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * 8164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * 10164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * Unless required by applicable law or agreed to in writing, software 11164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * See the License for the specific language governing permissions and 14164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian * limitations under the License. 15164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian */ 16164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 17f75a23d54cc9e5f7b6b976e65b6ec346178f306dMartijn Coenen#ifndef ANDROID_HARDWARE_PROCESS_STATE_H 18f75a23d54cc9e5f7b6b976e65b6ec346178f306dMartijn Coenen#define ANDROID_HARDWARE_PROCESS_STATE_H 19164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 204080edcfb5810a4a1817c03740f5f1bb19815ae1Martijn Coenen#include <hwbinder/IBinder.h> 21164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian#include <utils/KeyedVector.h> 22164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian#include <utils/String8.h> 23164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian#include <utils/String16.h> 24164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 25164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian#include <utils/threads.h> 26164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 272e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale#include <pthread.h> 282e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale 29164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian// --------------------------------------------------------------------------- 30164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopiannamespace android { 31f75a23d54cc9e5f7b6b976e65b6ec346178f306dMartijn Coenennamespace hardware { 32164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 33164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopianclass IPCThreadState; 34164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 35164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopianclass ProcessState : public virtual RefBase 36164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian{ 37164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopianpublic: 38164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian static sp<ProcessState> self(); 3985966ba503e89311ad92c1047b6067020f347488Colin Cross static sp<ProcessState> selfOrNull(); 40164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 41164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian void setContextObject(const sp<IBinder>& object); 42164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian sp<IBinder> getContextObject(const sp<IBinder>& caller); 43ab00b6a91986c8bb1ae70ca6a043e6a8facd254bMartijn Coenen 44164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian void setContextObject(const sp<IBinder>& object, 45164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian const String16& name); 46164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian sp<IBinder> getContextObject(const String16& name, 47164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian const sp<IBinder>& caller); 48164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 49164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian void startThreadPool(); 50ab00b6a91986c8bb1ae70ca6a043e6a8facd254bMartijn Coenen 51164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian typedef bool (*context_check_func)(const String16& name, 52164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian const sp<IBinder>& caller, 53164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian void* userData); 54ab00b6a91986c8bb1ae70ca6a043e6a8facd254bMartijn Coenen 55164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian bool isContextManager(void) const; 56164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian bool becomeContextManager( 57164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian context_check_func checkFunc, 58164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian void* userData); 59164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 60164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian sp<IBinder> getStrongProxyForHandle(int32_t handle); 61164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian wp<IBinder> getWeakProxyForHandle(int32_t handle); 62164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian void expungeHandle(int32_t handle, IBinder* binder); 63164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 64164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian void spawnPooledThread(bool isMain); 65ab00b6a91986c8bb1ae70ca6a043e6a8facd254bMartijn Coenen 66ab00b6a91986c8bb1ae70ca6a043e6a8facd254bMartijn Coenen status_t setThreadPoolConfiguration(size_t maxThreads, bool callerJoinsPool); 67d191ed717f5769d0c0a240ff94e004d7eb08d614Mathias Agopian void giveThreadPoolName(); 688297f5006d558d8774372774e901aab273b89624Mathias Agopian 6985966ba503e89311ad92c1047b6067020f347488Colin Cross ssize_t getKernelReferences(size_t count, uintptr_t* buf); 7085966ba503e89311ad92c1047b6067020f347488Colin Cross 71164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopianprivate: 72164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian friend class IPCThreadState; 73ab00b6a91986c8bb1ae70ca6a043e6a8facd254bMartijn Coenen 74164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian ProcessState(); 75164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian ~ProcessState(); 76164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 77164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian ProcessState(const ProcessState& o); 78164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian ProcessState& operator=(const ProcessState& o); 79d191ed717f5769d0c0a240ff94e004d7eb08d614Mathias Agopian String8 makeBinderThreadName(); 802e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale 81164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian struct handle_entry { 82164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian IBinder* binder; 83164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian RefBase::weakref_type* refs; 84164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian }; 852e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale 86164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian handle_entry* lookupHandleLocked(int32_t handle); 87164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 88164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian int mDriverFD; 89164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian void* mVMStart; 902e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale 912e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale // Protects thread count variable below. 922e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale pthread_mutex_t mThreadCountLock; 932e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale pthread_cond_t mThreadCountDecrement; 942e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale // Number of binder threads current executing a command. 952e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale size_t mExecutingThreadsCount; 962e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale // Maximum number for binder threads allowed for this process. 972e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale size_t mMaxThreads; 98b1dc654b9dbf8640605629a64b646ef1577c0db9Colin Cross // Time when thread pool was emptied 99b1dc654b9dbf8640605629a64b646ef1577c0db9Colin Cross int64_t mStarvationStartTimeMs; 1002e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale 101164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian mutable Mutex mLock; // protects everything below. 1022e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale 103164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian Vector<handle_entry>mHandleToObject; 104164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 105164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian bool mManagesContexts; 106164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian context_check_func mBinderContextCheckFunc; 107164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian void* mBinderContextUserData; 1082e604f066e712d99b5cd8ba4115f7ed2578d4a5dWale Ogunwale 109164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian KeyedVector<String16, sp<IBinder> > 110164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian mContexts; 111164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 112164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 113164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian String8 mRootDir; 114164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian bool mThreadPoolStarted; 115ab00b6a91986c8bb1ae70ca6a043e6a8facd254bMartijn Coenen bool mSpawnThreadOnStart; 116164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian volatile int32_t mThreadPoolSeq; 117164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian}; 118ab00b6a91986c8bb1ae70ca6a043e6a8facd254bMartijn Coenen 119f75a23d54cc9e5f7b6b976e65b6ec346178f306dMartijn Coenen}; // namespace hardware 120164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian}; // namespace android 121164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 122164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian// --------------------------------------------------------------------------- 123164757037f944dae1eb5f76176570b2e43a37b55Mathias Agopian 124f75a23d54cc9e5f7b6b976e65b6ec346178f306dMartijn Coenen#endif // ANDROID_HARDWARE_PROCESS_STATE_H 125