GCC Code Coverage Report


Directory: src/
File: src/LB_core/thread_ctx.c
Date: 2026-09-15 07:37:49
Exec Total Coverage
Lines: 17 22 77.3%
Functions: 3 4 75.0%
Branches: 10 18 55.6%

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 #include "LB_core/thread_ctx.h"
21 #include "support/debug.h"
22 #include <stdbool.h>
23
24 __thread thread_role_t thread_role = THREAD_ROLE_UNKNOWN;
25
26 125 void thread_ctx_set_main(thread_main_mode_t main_mode) {
27
28
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 125 times.
125 ensure(thread_role != THREAD_ROLE_WORKER,
29 "Wrong previous thread role in %s (%d). Please, report bug.",
30 __func__, thread_role);
31
32 125 thread_role =
33 main_mode == THREAD_MAIN_SEQUENTIAL ? THREAD_ROLE_MAIN_SEQUENTIAL
34
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 123 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
125 : main_mode == THREAD_MAIN_PARALLEL ? THREAD_ROLE_MAIN_PARALLEL
35 : THREAD_ROLE_UNKNOWN;
36
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 125 times.
125 ensure(thread_role != THREAD_ROLE_UNKNOWN,
38 "Unhandled thread main mode in %s. Please, report bug.",
39 __func__);
40 125 }
41
42 2 void thread_ctx_set_worker(void) {
43
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 ensure(thread_role == THREAD_ROLE_UNKNOWN,
45 "Wrong previous thread role in %s (%d). Please, report bug.",
46 __func__, thread_role);
47
48 2 thread_role = THREAD_ROLE_WORKER;
49 2 }
50
51 11 void thread_ctx_set_observer(bool is_observer) {
52
53 static __thread thread_role_t previous_thread_role = THREAD_ROLE_UNKNOWN;
54
55
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_observer
56
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 4 times.
11 && thread_role != THREAD_ROLE_OBSERVER) {
57 7 previous_thread_role = thread_role;
58 7 thread_role = THREAD_ROLE_OBSERVER;
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 } else if (!is_observer
60 && thread_role == THREAD_ROLE_OBSERVER) {
61 thread_role = previous_thread_role;
62 previous_thread_role = THREAD_ROLE_UNKNOWN;
63 }
64 11 }
65
66 void thread_ctx_reset_after_fork(void) {
67 thread_role = THREAD_ROLE_UNKNOWN;
68 }
69