1 | /* |
2 | * Copyright 2017-present Facebook, Inc. |
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 | #pragma once |
18 | |
19 | #include <memory> |
20 | #include <string> |
21 | #include <vector> |
22 | |
23 | #include <folly/Indestructible.h> |
24 | #include <folly/Synchronized.h> |
25 | #include <folly/ThreadLocal.h> |
26 | |
27 | namespace folly { |
28 | |
29 | /** |
30 | * A hook for tracking which threads belong to which thread pools. |
31 | * This is used only by a gdb extension to aid in debugging. You won't be able |
32 | * to see any useful information from within C++ code. |
33 | * |
34 | * An instance of ThreadPoolListHook should be created in the thread pool class |
35 | * that you want to keep track of. Then, to register a thread you call |
36 | * registerThread() on your instance of ThreadPoolListHook from that thread. |
37 | * |
38 | * When a thread exits it will be removed from the list |
39 | * When the thread pool is destroyed, it will be removed from the list |
40 | */ |
41 | class ThreadPoolListHook { |
42 | public: |
43 | /** |
44 | * Name is used to identify the thread pool when listing threads. |
45 | */ |
46 | explicit ThreadPoolListHook(std::string name); |
47 | ~ThreadPoolListHook(); |
48 | |
49 | /** |
50 | * Call this from any new thread that the thread pool creates. |
51 | */ |
52 | void registerThread(); |
53 | |
54 | ThreadPoolListHook(const ThreadPoolListHook& other) = delete; |
55 | ThreadPoolListHook& operator=(const ThreadPoolListHook&) = delete; |
56 | |
57 | private: |
58 | ThreadPoolListHook(); |
59 | }; |
60 | |
61 | } // namespace folly |
62 | |