GCC Code Coverage Report


Directory: ./
File: libs/capy/src/ex/execution_context.cpp
Date: 2026-01-15 23:24:40
Exec Total Coverage
Lines: 61 67 91.0%
Functions: 7 7 100.0%
Branches: 37 47 78.7%

Line Branch Exec Source
1 //
2 // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/capy
8 //
9
10 #include <boost/capy/ex/execution_context.hpp>
11 #include <boost/capy/detail/except.hpp>
12
13 namespace boost {
14 namespace capy {
15
16 26 execution_context::
17 execution_context() = default;
18
19 26 execution_context::
20 ~execution_context()
21 {
22 26 shutdown();
23 26 destroy();
24 26 }
25
26 void
27 40 execution_context::
28 shutdown() noexcept
29 {
30
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 26 times.
40 if(shutdown_)
31 14 return;
32 26 shutdown_ = true;
33
34 26 service* p = head_;
35
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 26 times.
41 while(p)
36 {
37 15 p->shutdown();
38 15 p = p->next_;
39 }
40 }
41
42 void
43 40 execution_context::
44 destroy() noexcept
45 {
46 40 service* p = head_;
47 40 head_ = nullptr;
48
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 40 times.
55 while(p)
49 {
50 15 service* next = p->next_;
51
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 delete p;
52 15 p = next;
53 }
54 40 }
55
56 execution_context::service*
57 67 execution_context::
58 find_impl(std::type_index ti) const noexcept
59 {
60 67 auto p = head_;
61
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 37 times.
74 while(p)
62 {
63
6/6
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 26 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 30 times.
✓ Branch 7 taken 7 times.
37 if(p->t0_ == ti || p->t1_ == ti)
64 30 break;
65 7 p = p->next_;
66 }
67 67 return p;
68 }
69
70 execution_context::service&
71 17 execution_context::
72 use_service_impl(factory& f)
73 {
74
1/1
✓ Branch 1 taken 17 times.
17 std::unique_lock<std::mutex> lock(mutex_);
75
76
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 8 times.
17 if(auto* p = find_impl(f.t0))
77 9 return *p;
78
79
1/1
✓ Branch 1 taken 8 times.
8 lock.unlock();
80
81 // Create the service outside lock, enabling nested calls
82
1/1
✓ Branch 1 taken 8 times.
8 service* sp = f.create(*this);
83 8 sp->t0_ = f.t0;
84 8 sp->t1_ = f.t1;
85
86
1/1
✓ Branch 1 taken 8 times.
8 lock.lock();
87
88
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if(auto* p = find_impl(f.t0))
89 {
90 delete sp;
91 return *p;
92 }
93
94 8 sp->next_ = head_;
95 8 head_ = sp;
96
97 8 return *sp;
98 17 }
99
100 execution_context::service&
101 10 execution_context::
102 make_service_impl(factory& f)
103 {
104 {
105
1/1
✓ Branch 1 taken 10 times.
10 std::lock_guard<std::mutex> lock(mutex_);
106
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8 times.
10 if(find_impl(f.t0))
107 2 detail::throw_invalid_argument();
108
6/6
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 7 times.
8 if(f.t0 != f.t1 && find_impl(f.t1))
109 1 detail::throw_invalid_argument();
110 10 }
111
112 // Unlocked to allow nested service creation from constructor
113
1/1
✓ Branch 1 taken 7 times.
7 service* p = f.create(*this);
114
115
1/1
✓ Branch 1 taken 7 times.
7 std::lock_guard<std::mutex> lock(mutex_);
116
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
7 if(find_impl(f.t0))
117 {
118 delete p;
119 detail::throw_invalid_argument();
120 }
121
122 7 p->t0_ = f.t0;
123
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 6 times.
7 if(f.t0 != f.t1)
124 {
125
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if(find_impl(f.t1))
126 {
127 delete p;
128 detail::throw_invalid_argument();
129 }
130 1 p->t1_ = f.t1;
131 }
132 else
133 {
134 6 p->t1_ = f.t0;
135 }
136
137 7 p->next_ = head_;
138 7 head_ = p;
139
140 7 return *p;
141 7 }
142
143 } // namespace capy
144 } // namespace boost
145