2 * Copyright (C) 2005 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_PROCESS_STATE_H
18 #define ANDROID_PROCESS_STATE_H
20 #include <binder/IBinder.h>
21 #include <utils/KeyedVector.h>
22 #include <utils/String8.h>
23 #include <utils/String16.h>
25 #include <utils/threads.h>
29 // ---------------------------------------------------------------------------
34 class ProcessState : public virtual RefBase
37 static sp<ProcessState> self();
38 static sp<ProcessState> selfOrNull();
39 /* initWithDriver() can be used to configure libbinder to use
40 * a different binder driver dev node. It must be called *before*
41 * any call to ProcessState::self(). /dev/binder remains the default.
43 static sp<ProcessState> initWithDriver(const char *driver);
45 void setContextObject(const sp<IBinder>& object);
46 sp<IBinder> getContextObject(const sp<IBinder>& caller);
48 void setContextObject(const sp<IBinder>& object,
49 const String16& name);
50 sp<IBinder> getContextObject(const String16& name,
51 const sp<IBinder>& caller);
53 void startThreadPool();
55 typedef bool (*context_check_func)(const String16& name,
56 const sp<IBinder>& caller,
59 bool isContextManager(void) const;
60 bool becomeContextManager(
61 context_check_func checkFunc,
64 sp<IBinder> getStrongProxyForHandle(int32_t handle);
65 wp<IBinder> getWeakProxyForHandle(int32_t handle);
66 void expungeHandle(int32_t handle, IBinder* binder);
68 void spawnPooledThread(bool isMain);
70 status_t setThreadPoolMaxThreadCount(size_t maxThreads);
71 void giveThreadPoolName();
73 String8 getDriverName();
75 ssize_t getKernelReferences(size_t count, uintptr_t* buf);
78 friend class IPCThreadState;
80 ProcessState(const char* driver);
83 ProcessState(const ProcessState& o);
84 ProcessState& operator=(const ProcessState& o);
85 String8 makeBinderThreadName();
89 RefBase::weakref_type* refs;
92 handle_entry* lookupHandleLocked(int32_t handle);
98 // Protects thread count variable below.
99 pthread_mutex_t mThreadCountLock;
100 pthread_cond_t mThreadCountDecrement;
101 // Number of binder threads current executing a command.
102 size_t mExecutingThreadsCount;
103 // Maximum number for binder threads allowed for this process.
105 // Time when thread pool was emptied
106 int64_t mStarvationStartTimeMs;
108 mutable Mutex mLock; // protects everything below.
110 Vector<handle_entry>mHandleToObject;
112 bool mManagesContexts;
113 context_check_func mBinderContextCheckFunc;
114 void* mBinderContextUserData;
116 KeyedVector<String16, sp<IBinder> >
121 bool mThreadPoolStarted;
122 volatile int32_t mThreadPoolSeq;
125 }; // namespace android
127 // ---------------------------------------------------------------------------
129 #endif // ANDROID_PROCESS_STATE_H