Directory: | ./ |
---|---|
File: | include/shared_memory/exchange_manager_producer.hxx |
Date: | 2022-06-30 06:29:57 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 61 | 69 | 88.4% |
Branches: | 30 | 64 | 46.9% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | template <class Serializable, int QUEUE_SIZE> | ||
3 | 2 | Exchange_manager_producer<Serializable, QUEUE_SIZE>::Exchange_manager_producer( | |
4 | 2 | std::string segment_id, std::string object_id, bool leading, bool autolock) | |
5 | { | ||
6 | 2 | leading_ = leading; | |
7 | 2 | autolock_ = autolock; | |
8 | |||
9 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | segment_id_ = segment_id; |
10 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | object_id_ = object_id; |
11 | |||
12 |
5/10✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | memory_.reset(new Memory(segment_id, object_id)); |
13 | |||
14 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (leading) |
15 | { | ||
16 | // if leading, waiting for a consumer to change the status | ||
17 | // to ready | ||
18 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | memory_->set_status(Memory::Status::WAITING); |
19 | } | ||
20 | else | ||
21 | { | ||
22 | // if not leading, informing the (leading) consumer | ||
23 | // that this producer is ready | ||
24 | ✗ | memory_->set_status(Memory::Status::RUNNING); | |
25 | } | ||
26 | 2 | } | |
27 | |||
28 | template <class Serializable, int QUEUE_SIZE> | ||
29 | 2 | Exchange_manager_producer<Serializable, | |
30 | QUEUE_SIZE>::~Exchange_manager_producer() | ||
31 | { | ||
32 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (leading_) |
33 | { | ||
34 | 2 | memory_->clean(); | |
35 | } | ||
36 | else | ||
37 | { | ||
38 | ✗ | memory_->set_status(Memory::Status::RESET); | |
39 | } | ||
40 | 2 | } | |
41 | |||
42 | template <class Serializable, int QUEUE_SIZE> | ||
43 | 9 | void Exchange_manager_producer<Serializable, QUEUE_SIZE>::reset() | |
44 | { | ||
45 | 9 | memory_->clean(); | |
46 | 9 | memory_ = NULL; | |
47 |
4/8✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 9 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 9 times.
✗ Branch 12 not taken.
|
9 | memory_.reset(new Memory(segment_id_, object_id_)); |
48 | 9 | } | |
49 | |||
50 | template <class Serializable, int QUEUE_SIZE> | ||
51 | 284 | bool Exchange_manager_producer<Serializable, QUEUE_SIZE>::ready_to_produce() | |
52 | { | ||
53 | typename Memory::Status status; | ||
54 |
1/2✓ Branch 2 taken 284 times.
✗ Branch 3 not taken.
|
284 | memory_->get_status(status); |
55 | |||
56 |
2/2✓ Branch 0 taken 233 times.
✓ Branch 1 taken 51 times.
|
284 | if (status == Memory::Status::WAITING) |
57 | { | ||
58 | 233 | return false; | |
59 | } | ||
60 | |||
61 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 42 times.
|
51 | if (status == Memory::Status::RESET) |
62 | { | ||
63 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (leading_) |
64 | { | ||
65 | // a consumer died : reseting the memory | ||
66 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | this->reset(); |
67 |
1/2✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | memory_->set_status(Memory::Status::WAITING); |
68 | 9 | return false; | |
69 | } | ||
70 | else | ||
71 | { | ||
72 | // waiting for the leader to set back to waiting | ||
73 | ✗ | return false; | |
74 | } | ||
75 | } | ||
76 | |||
77 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | if (status == Memory::Status::RUNNING) |
78 | { | ||
79 | 42 | return true; | |
80 | } | ||
81 | |||
82 | ✗ | return false; | |
83 | } | ||
84 | |||
85 | template <class Serializable, int QUEUE_SIZE> | ||
86 | 2022 | void Exchange_manager_producer<Serializable, QUEUE_SIZE>::lock() | |
87 | { | ||
88 | 2022 | memory_->lock(); | |
89 | 2022 | } | |
90 | |||
91 | template <class Serializable, int QUEUE_SIZE> | ||
92 | 2022 | void Exchange_manager_producer<Serializable, QUEUE_SIZE>::unlock() | |
93 | { | ||
94 | 2022 | memory_->unlock(); | |
95 | 2022 | } | |
96 | |||
97 | template <class Serializable, int QUEUE_SIZE> | ||
98 | void Exchange_manager_producer<Serializable, QUEUE_SIZE>::clear() | ||
99 | { | ||
100 | memory_->clear(); | ||
101 | } | ||
102 | |||
103 | template <class Serializable, int QUEUE_SIZE> | ||
104 | 1000 | bool Exchange_manager_producer<Serializable, QUEUE_SIZE>::set( | |
105 | const Serializable &serializable) | ||
106 | { | ||
107 | bool everything_shared; | ||
108 | |||
109 |
1/2✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
|
1000 | if (autolock_) |
110 | { | ||
111 | 1000 | this->lock(); | |
112 | } | ||
113 | |||
114 | try | ||
115 | { | ||
116 |
1/2✓ Branch 2 taken 1000 times.
✗ Branch 3 not taken.
|
1000 | everything_shared = memory_->write_serialized(serializable); |
117 | } | ||
118 | ✗ | catch (const std::runtime_error &e) | |
119 | { | ||
120 | ✗ | if (autolock_) | |
121 | { | ||
122 | ✗ | this->unlock(); | |
123 | } | ||
124 | ✗ | throw e; | |
125 | } | ||
126 | |||
127 |
1/2✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
|
1000 | if (autolock_) |
128 | { | ||
129 | 1000 | this->unlock(); | |
130 | } | ||
131 | |||
132 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
1000 | return everything_shared; |
133 | } | ||
134 | |||
135 | template <class Serializable, int QUEUE_SIZE> | ||
136 | 1022 | void Exchange_manager_producer<Serializable, QUEUE_SIZE>::get( | |
137 | std::deque<int> &get_consumed_ids) | ||
138 | { | ||
139 |
1/2✓ Branch 0 taken 1022 times.
✗ Branch 1 not taken.
|
1022 | if (autolock_) |
140 | { | ||
141 | 1022 | this->lock(); | |
142 | } | ||
143 | |||
144 | 1022 | memory_->get_consumed_ids(get_consumed_ids); | |
145 | |||
146 |
1/2✓ Branch 0 taken 1022 times.
✗ Branch 1 not taken.
|
1022 | if (autolock_) |
147 | { | ||
148 | 1022 | this->unlock(); | |
149 | } | ||
150 | |||
151 | 1022 | return; | |
152 | } | ||
153 | |||
154 | template <class Serializable, int QUEUE_SIZE> | ||
155 | 10 | void Exchange_manager_producer<Serializable, QUEUE_SIZE>::reset_char_count() | |
156 | { | ||
157 | 10 | memory_->reset_char_count(); | |
158 | 10 | } | |
159 | |||
160 | template <class Serializable, int QUEUE_SIZE> | ||
161 | 1022 | int Exchange_manager_producer<Serializable, QUEUE_SIZE>::nb_char_written() | |
162 | { | ||
163 | 1022 | return memory_->nb_char_written(); | |
164 | } | ||
165 | |||
166 | template <class Serializable, int QUEUE_SIZE> | ||
167 | 2 | void Exchange_manager_producer<Serializable, QUEUE_SIZE>::clean_mutex( | |
168 | std::string segment_id) | ||
169 | { | ||
170 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | Exchange_manager_memory<Serializable, QUEUE_SIZE>::clean_mutex(segment_id); |
171 | 2 | } | |
172 | |||
173 | template <class Serializable, int QUEUE_SIZE> | ||
174 | 2 | void Exchange_manager_producer<Serializable, QUEUE_SIZE>::clean_memory( | |
175 | std::string segment_id) | ||
176 | { | ||
177 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | Exchange_manager_memory<Serializable, QUEUE_SIZE>::clean_memory(segment_id); |
178 | 2 | } | |
179 | |||
180 | template <class Serializable, int QUEUE_SIZE> | ||
181 | bool Exchange_manager_producer<Serializable, QUEUE_SIZE>::producer_queue_empty() | ||
182 | const | ||
183 | { | ||
184 | return memory_->producer_queue_empty(); | ||
185 | } | ||
186 | |||
187 | template <class Serializable, int QUEUE_SIZE> | ||
188 | bool Exchange_manager_producer<Serializable, QUEUE_SIZE>::consumer_queue_empty() | ||
189 | const | ||
190 | { | ||
191 | return memory_->consumer_queue_empty(); | ||
192 | } | ||
193 |