32 class ThreadListHook {
34 ThreadListHook(ThreadPoolListHook* poolId, std::thread::id threadId);
43 class GlobalThreadPoolListImpl {
45 GlobalThreadPoolListImpl() {}
47 void registerThreadPool(ThreadPoolListHook* threadPoolId,
std::string name);
49 void unregisterThreadPool(ThreadPoolListHook* threadPoolId);
51 void registerThreadPoolThread(
52 ThreadPoolListHook* threadPoolId,
53 std::thread::id threadId);
55 void unregisterThreadPoolThread(
56 ThreadPoolListHook* threadPoolId,
57 std::thread::id threadId);
72 getThreadVector(
void* threadPoolId) {
73 for (
auto& elem :
vector()) {
74 if (elem.addr == threadPoolId) {
82 std::vector<PoolInfo>&
vector() {
90 class GlobalThreadPoolList {
92 GlobalThreadPoolList() {}
94 static GlobalThreadPoolList& instance();
96 void registerThreadPool(ThreadPoolListHook* threadPoolId,
std::string name);
98 void unregisterThreadPool(ThreadPoolListHook* threadPoolId);
100 void registerThreadPoolThread(
101 ThreadPoolListHook* threadPoolId,
102 std::thread::id threadId);
104 void unregisterThreadPoolThread(
105 ThreadPoolListHook* threadPoolId,
106 std::thread::id threadId);
108 GlobalThreadPoolList(GlobalThreadPoolList
const&) =
delete;
109 void operator=(GlobalThreadPoolList
const&) =
delete;
118 GlobalThreadPoolList& GlobalThreadPoolList::instance() {
123 void GlobalThreadPoolList::registerThreadPool(
124 ThreadPoolListHook* threadPoolId,
129 void GlobalThreadPoolList::unregisterThreadPool(
130 ThreadPoolListHook* threadPoolId) {
134 void GlobalThreadPoolList::registerThreadPoolThread(
135 ThreadPoolListHook* threadPoolId,
136 std::thread::id threadId) {
138 threadHook_.reset(make_unique<ThreadListHook>(threadPoolId, threadId));
143 void GlobalThreadPoolList::unregisterThreadPoolThread(
144 ThreadPoolListHook* threadPoolId,
145 std::thread::id threadId) {
151 void GlobalThreadPoolListImpl::registerThreadPool(
152 ThreadPoolListHook* threadPoolId,
156 info.addr = threadPoolId;
157 pools_.vector().push_back(info);
160 void GlobalThreadPoolListImpl::unregisterThreadPool(
161 ThreadPoolListHook* threadPoolId) {
167 [=](PoolInfo&
i) {
return i.addr == threadPoolId; }),
171 void GlobalThreadPoolListImpl::registerThreadPoolThread(
172 ThreadPoolListHook* threadPoolId,
173 std::thread::id threadId) {
174 auto vec =
pools_.getThreadVector(threadPoolId);
175 if (
vec ==
nullptr) {
179 vec->push_back(threadId);
182 void GlobalThreadPoolListImpl::unregisterThreadPoolThread(
183 ThreadPoolListHook* threadPoolId,
184 std::thread::id threadId) {
185 auto vec =
pools_.getThreadVector(threadPoolId);
186 if (
vec ==
nullptr) {
190 vec->erase(std::remove(
vec->begin(),
vec->end(), threadId),
vec->end());
193 ThreadListHook::ThreadListHook(
194 ThreadPoolListHook* poolId,
195 std::thread::id threadId) {
200 ThreadListHook::~ThreadListHook() {
201 GlobalThreadPoolList::instance().unregisterThreadPoolThread(
206 GlobalThreadPoolList::instance().registerThreadPool(
this, name);
210 GlobalThreadPoolList::instance().unregisterThreadPool(
this);
214 GlobalThreadPoolList::instance().registerThreadPoolThread(
215 this, std::this_thread::get_id());
folly::Synchronized< GlobalThreadPoolListImpl > globalListImpl_
std::thread::id threadId_
ThreadPoolListHook * poolId_
—— Concurrent Priority Queue Implementation ——
std::vector< std::thread::id > threads
folly::ThreadLocalPtr< ThreadListHook > threadHook_
ThreadPoolListHook * addr
std::vector< PoolInfo > poolsInfo_