]>
Commit | Line | Data |
---|---|---|
ee4512ed JH |
1 | #ifndef TR2_TLS_H |
2 | #define TR2_TLS_H | |
3 | ||
4 | #include "strbuf.h" | |
5 | ||
5bbb9251 JH |
6 | /* |
7 | * Notice: the term "TLS" refers to "thread-local storage" in the | |
8 | * Trace2 source files. This usage is borrowed from GCC and Windows. | |
9 | * There is NO relation to "transport layer security". | |
10 | */ | |
11 | ||
ee4512ed JH |
12 | /* |
13 | * Arbitry limit for thread names for column alignment. | |
14 | */ | |
15 | #define TR2_MAX_THREAD_NAME (24) | |
16 | ||
17 | struct tr2tls_thread_ctx { | |
18 | struct strbuf thread_name; | |
19 | uint64_t *array_us_start; | |
545ddca0 JH |
20 | size_t alloc; |
21 | size_t nr_open_regions; /* plays role of "nr" in ALLOC_GROW */ | |
ee4512ed JH |
22 | int thread_id; |
23 | }; | |
24 | ||
25 | /* | |
5bbb9251 | 26 | * Create thread-local storage for the current thread. |
ee4512ed JH |
27 | * |
28 | * We assume the first thread is "main". Other threads are given | |
29 | * non-zero thread-ids to help distinguish messages from concurrent | |
30 | * threads. | |
31 | * | |
32 | * Truncate the thread name if necessary to help with column alignment | |
33 | * in printf-style messages. | |
34 | * | |
35 | * In this and all following functions the term "self" refers to the | |
36 | * current thread. | |
37 | */ | |
a0897249 JH |
38 | struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name, |
39 | uint64_t us_thread_start); | |
ee4512ed JH |
40 | |
41 | /* | |
5bbb9251 | 42 | * Get the thread-local storage pointer of the current thread. |
ee4512ed JH |
43 | */ |
44 | struct tr2tls_thread_ctx *tr2tls_get_self(void); | |
45 | ||
46 | /* | |
47 | * return true if the current thread is the main thread. | |
48 | */ | |
49 | int tr2tls_is_main_thread(void); | |
50 | ||
51 | /* | |
5bbb9251 | 52 | * Free the current thread's thread-local storage. |
ee4512ed JH |
53 | */ |
54 | void tr2tls_unset_self(void); | |
55 | ||
56 | /* | |
57 | * Begin a new nested region and remember the start time. | |
58 | */ | |
59 | void tr2tls_push_self(uint64_t us_now); | |
60 | ||
61 | /* | |
62 | * End the innermost nested region. | |
63 | */ | |
64 | void tr2tls_pop_self(void); | |
65 | ||
66 | /* | |
67 | * Pop any extra (above the first) open regions on the current | |
68 | * thread and discard. During a thread-exit, we should only | |
69 | * have region[0] that was pushed in trace2_thread_start() if | |
70 | * the thread exits normally. | |
71 | */ | |
72 | void tr2tls_pop_unwind_self(void); | |
73 | ||
74 | /* | |
75 | * Compute the elapsed time since the innermost region in the | |
76 | * current thread started and the given time (usually now). | |
77 | */ | |
78 | uint64_t tr2tls_region_elasped_self(uint64_t us); | |
79 | ||
80 | /* | |
81 | * Compute the elapsed time since the main thread started | |
82 | * and the given time (usually now). This is assumed to | |
83 | * be the absolute run time of the process. | |
84 | */ | |
85 | uint64_t tr2tls_absolute_elapsed(uint64_t us); | |
86 | ||
87 | /* | |
5bbb9251 | 88 | * Initialize thread-local storage for Trace2. |
ee4512ed JH |
89 | */ |
90 | void tr2tls_init(void); | |
91 | ||
92 | /* | |
5bbb9251 | 93 | * Free all Trace2 thread-local storage resources. |
ee4512ed JH |
94 | */ |
95 | void tr2tls_release(void); | |
96 | ||
97 | /* | |
98 | * Protected increment of an integer. | |
99 | */ | |
100 | int tr2tls_locked_increment(int *p); | |
101 | ||
a0897249 JH |
102 | /* |
103 | * Capture the process start time and do nothing else. | |
104 | */ | |
105 | void tr2tls_start_process_clock(void); | |
106 | ||
ee4512ed | 107 | #endif /* TR2_TLS_H */ |