| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2005 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #ifndef ANDROID_PROCESS_STATE_H | 
|  | 18 | #define ANDROID_PROCESS_STATE_H | 
|  | 19 |  | 
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 20 | #include <binder/IBinder.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <utils/KeyedVector.h> | 
|  | 22 | #include <utils/String8.h> | 
|  | 23 | #include <utils/String16.h> | 
|  | 24 |  | 
|  | 25 | #include <utils/threads.h> | 
|  | 26 |  | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 27 | #include <pthread.h> | 
|  | 28 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | // --------------------------------------------------------------------------- | 
|  | 30 | namespace android { | 
|  | 31 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | class IPCThreadState; | 
|  | 33 |  | 
|  | 34 | class ProcessState : public virtual RefBase | 
|  | 35 | { | 
|  | 36 | public: | 
|  | 37 | static  sp<ProcessState>    self(); | 
|  | 38 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | void                setContextObject(const sp<IBinder>& object); | 
|  | 40 | sp<IBinder>         getContextObject(const sp<IBinder>& caller); | 
|  | 41 |  | 
|  | 42 | void                setContextObject(const sp<IBinder>& object, | 
|  | 43 | const String16& name); | 
|  | 44 | sp<IBinder>         getContextObject(const String16& name, | 
|  | 45 | const sp<IBinder>& caller); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 |  | 
|  | 47 | void                startThreadPool(); | 
|  | 48 |  | 
|  | 49 | typedef bool (*context_check_func)(const String16& name, | 
|  | 50 | const sp<IBinder>& caller, | 
|  | 51 | void* userData); | 
|  | 52 |  | 
|  | 53 | bool                isContextManager(void) const; | 
|  | 54 | bool                becomeContextManager( | 
|  | 55 | context_check_func checkFunc, | 
|  | 56 | void* userData); | 
|  | 57 |  | 
|  | 58 | sp<IBinder>         getStrongProxyForHandle(int32_t handle); | 
|  | 59 | wp<IBinder>         getWeakProxyForHandle(int32_t handle); | 
|  | 60 | void                expungeHandle(int32_t handle, IBinder* binder); | 
|  | 61 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | void                spawnPooledThread(bool isMain); | 
|  | 63 |  | 
| Mathias Agopian | 1b80f79 | 2012-04-17 16:11:08 -0700 | [diff] [blame] | 64 | status_t            setThreadPoolMaxThreadCount(size_t maxThreads); | 
| Mathias Agopian | e3e43b3 | 2013-03-07 15:34:28 -0800 | [diff] [blame] | 65 | void                giveThreadPoolName(); | 
| Mathias Agopian | 1b80f79 | 2012-04-17 16:11:08 -0700 | [diff] [blame] | 66 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | private: | 
|  | 68 | friend class IPCThreadState; | 
|  | 69 |  | 
|  | 70 | ProcessState(); | 
|  | 71 | ~ProcessState(); | 
|  | 72 |  | 
|  | 73 | ProcessState(const ProcessState& o); | 
|  | 74 | ProcessState&       operator=(const ProcessState& o); | 
| Mathias Agopian | e3e43b3 | 2013-03-07 15:34:28 -0800 | [diff] [blame] | 75 | String8             makeBinderThreadName(); | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 76 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | struct handle_entry { | 
|  | 78 | IBinder* binder; | 
|  | 79 | RefBase::weakref_type* refs; | 
|  | 80 | }; | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 81 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | handle_entry*       lookupHandleLocked(int32_t handle); | 
|  | 83 |  | 
|  | 84 | int                 mDriverFD; | 
|  | 85 | void*               mVMStart; | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 86 |  | 
|  | 87 | // Protects thread count variable below. | 
|  | 88 | pthread_mutex_t     mThreadCountLock; | 
|  | 89 | pthread_cond_t      mThreadCountDecrement; | 
|  | 90 | // Number of binder threads current executing a command. | 
|  | 91 | size_t              mExecutingThreadsCount; | 
|  | 92 | // Maximum number for binder threads allowed for this process. | 
|  | 93 | size_t              mMaxThreads; | 
|  | 94 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | mutable Mutex               mLock;  // protects everything below. | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 96 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | Vector<handle_entry>mHandleToObject; | 
|  | 98 |  | 
|  | 99 | bool                mManagesContexts; | 
|  | 100 | context_check_func  mBinderContextCheckFunc; | 
|  | 101 | void*               mBinderContextUserData; | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 102 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | KeyedVector<String16, sp<IBinder> > | 
|  | 104 | mContexts; | 
|  | 105 |  | 
|  | 106 |  | 
|  | 107 | String8             mRootDir; | 
|  | 108 | bool                mThreadPoolStarted; | 
|  | 109 | volatile int32_t            mThreadPoolSeq; | 
|  | 110 | }; | 
|  | 111 |  | 
|  | 112 | }; // namespace android | 
|  | 113 |  | 
|  | 114 | // --------------------------------------------------------------------------- | 
|  | 115 |  | 
|  | 116 | #endif // ANDROID_PROCESS_STATE_H |