blob: 0e5893db8106b7e8faefe96125820492ca01f7f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INCLUDE_KDBINDER_BINDER_PROCESSSTATE_H_
#define INCLUDE_KDBINDER_BINDER_PROCESSSTATE_H_
#include <binder/IBinder.h>
#include <kdbinder/kdbus/KDBinder.h>
#include <utils/RefBase.h>
#include <utils/Mutex.h>
#include <utils/String16.h>
#include <memory>
#include <vector>
namespace android {
class ProcessState : public virtual RefBase {
public:
static sp<ProcessState> self();
void startThreadPool();
void spawnPooledThread(bool isMain);
sp<IBinder> getStrongProxyForHandle(int32_t handle);
status_t setThreadPoolMaxThreadCount(size_t maxThreads);
private:
friend class IPCThreadState;
// BpServiceManager needs to call registerService.
friend class BpServiceManager;
ProcessState();
~ProcessState() = default;
ProcessState(const ProcessState& o);
ProcessState& operator=(const ProcessState& o);
// Number of thread to spawn in the pool.
// TODO: tune this
static const int kThreadNum = 10;
// Add the given Binder object in mServiceTable.
int32_t registerService(sp<IBinder> binder, String16 name);
// Each Binder object managed by ProcessState need a kdbus::Connection
// associated with them.
struct binder_entry {
binder_entry(std::unique_ptr<kdbus::Connection> connection,
sp<IBinder> binder)
: connection(std::move(connection)),
binder(binder) {}
std::shared_ptr<kdbus::Connection> connection;
sp<IBinder> binder;
};
mutable Mutex mLock; // protects everything below.
bool mThreadPoolStarted;
volatile int32_t mThreadPoolSeq;
mutable Mutex mServiceLock;
std::vector<struct binder_entry> mServiceTable;
};
} // namespace android
#endif // INCLUDE_KDBINDER_BINDER_PROCESSSTATE_H_
|