GCC Code Coverage Report


Directory: src/
File: src/LB_core/thread_ctx.h
Date: 2026-09-15 07:37:49
Exec Total Coverage
Lines: 13 14 92.9%
Functions: 5 5 100.0%
Branches: 9 14 64.3%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2026 Barcelona Supercomputing Center */
3 /* */
4 /* This file is part of the DLB library. */
5 /* */
6 /* DLB is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU Lesser General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* DLB is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU Lesser General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU Lesser General Public License */
17 /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18 /*********************************************************************************/
19
20 #ifndef THREAD_CTX_H
21 #define THREAD_CTX_H
22
23 #include <stdbool.h>
24
25 typedef enum {
26 THREAD_ROLE_UNKNOWN = 0, /* default; not yet classified */
27 THREAD_ROLE_MAIN_SEQUENTIAL, /* set in DLB_init() */
28 THREAD_ROLE_MAIN_PARALLEL, /* detected via OMPT parallel_begin */
29 THREAD_ROLE_WORKER, /* detected via OMPT thread_begin */
30 THREAD_ROLE_OBSERVER, /* calls the API but is never profiled */
31 } thread_role_t;
32
33 extern __thread thread_role_t thread_role;
34
35 38 static inline bool thread_is_main(void) {
36
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 return thread_role == THREAD_ROLE_MAIN_SEQUENTIAL ||
37 thread_role == THREAD_ROLE_MAIN_PARALLEL;
38 }
39
40 41 static inline bool thread_is_main_sequential(void) {
41 41 return thread_role == THREAD_ROLE_MAIN_SEQUENTIAL;
42 }
43
44 5553 static inline bool thread_is_parallel(void) {
45
1/2
✓ Branch 0 taken 5553 times.
✗ Branch 1 not taken.
11106 return thread_role == THREAD_ROLE_MAIN_PARALLEL ||
46
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5551 times.
5553 thread_role == THREAD_ROLE_WORKER;
47 }
48
49 11084 static inline bool thread_is_profiled(void) {
50 11099 return thread_role == THREAD_ROLE_MAIN_SEQUENTIAL ||
51
3/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 11069 times.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
11099 thread_role == THREAD_ROLE_MAIN_PARALLEL ||
52
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11 times.
15 thread_role == THREAD_ROLE_WORKER;
53 }
54
55 119 static inline bool thread_is_observer(void) {
56 119 return thread_role == THREAD_ROLE_OBSERVER;
57 }
58
59 typedef enum {
60 THREAD_MAIN_SEQUENTIAL,
61 THREAD_MAIN_PARALLEL,
62 } thread_main_mode_t;
63
64 void thread_ctx_set_main(thread_main_mode_t main_mode);
65 void thread_ctx_set_worker(void);
66 void thread_ctx_set_observer(bool is_observer);
67
68 void thread_ctx_reset_after_fork(void);
69
70 #endif /* THREAD_CTX_H */
71