GCC Code Coverage Report


Directory: ./
File: include/shared_memory/exchange_manager_consumer.hxx
Date: 2022-06-30 06:29:57
Exec Total Coverage
Lines: 39 56 69.6%
Branches: 19 58 32.8%

Line Branch Exec Source
1
2
3 template <class Serializable, int QUEUE_SIZE>
4 11 Exchange_manager_consumer<Serializable, QUEUE_SIZE>::Exchange_manager_consumer(
5 11 std::string segment_id, std::string object_id, bool leading, bool autolock)
6 {
7 11 leading_ = leading;
8 11 autolock_ = autolock;
9
10
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
11 segment_id_ = segment_id;
11
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
11 object_id_ = object_id;
12
13
5/10
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 11 times.
✗ Branch 14 not taken.
11 memory_.reset(new Memory(segment_id, object_id));
14
15
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (leading)
16 {
17 // if leading, waiting for a producer to change the status
18 // to ready
19 memory_->set_status(Memory::Status::WAITING);
20 }
21 else
22 {
23 // if not leading, informing the (leading) producer
24 // that this consumer is ready
25
1/2
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 memory_->set_status(Memory::Status::RUNNING);
26 }
27 11 }
28
29 template <class Serializable, int QUEUE_SIZE>
30 11 Exchange_manager_consumer<Serializable,
31 QUEUE_SIZE>::~Exchange_manager_consumer()
32 {
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (leading_)
34 {
35 memory_->clean();
36 }
37
38 else
39 {
40 11 memory_->set_status(Memory::Status::RESET);
41 }
42 11 }
43
44 template <class Serializable, int QUEUE_SIZE>
45 1017 bool Exchange_manager_consumer<Serializable, QUEUE_SIZE>::ready_to_consume()
46 {
47 typename Memory::Status status;
48
1/2
✓ Branch 2 taken 1017 times.
✗ Branch 3 not taken.
1017 memory_->get_status(status);
49
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1017 times.
1017 if (status == Memory::Status::WAITING)
51 {
52 return false;
53 }
54
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1017 times.
1017 if (status == Memory::Status::RESET)
56 {
57 if (leading_)
58 {
59 // producer died, reseting the memory
60 this->reset();
61 memory_->set_status(Memory::Status::WAITING);
62 return false;
63 }
64 else
65 {
66 // waiting for the leader to set back to waiting
67 return false;
68 }
69 }
70
71
1/2
✓ Branch 0 taken 1017 times.
✗ Branch 1 not taken.
1017 if (status == Memory::Status::RUNNING)
72 {
73 1017 return true;
74 }
75
76 return true;
77 }
78
79 template <class Serializable, int QUEUE_SIZE>
80 1017 void Exchange_manager_consumer<Serializable, QUEUE_SIZE>::lock()
81 {
82 1017 memory_->lock();
83 1017 }
84
85 template <class Serializable, int QUEUE_SIZE>
86 1017 void Exchange_manager_consumer<Serializable, QUEUE_SIZE>::unlock()
87 {
88 1017 memory_->unlock();
89 1017 }
90
91 template <class Serializable, int QUEUE_SIZE>
92 void Exchange_manager_consumer<Serializable, QUEUE_SIZE>::reset()
93 {
94 memory_->clean();
95 memory_ = NULL;
96 memory_.reset(new Memory(segment_id_, object_id_));
97 }
98
99 template <class Serializable, int QUEUE_SIZE>
100 10 bool Exchange_manager_consumer<Serializable, QUEUE_SIZE>::purge_feedbacks()
101 {
102 10 return memory_->purge_feedbacks();
103 }
104
105 template <class Serializable, int QUEUE_SIZE>
106 1017 bool Exchange_manager_consumer<Serializable, QUEUE_SIZE>::consume(
107 Serializable &serializable)
108 {
109
1/2
✓ Branch 0 taken 1017 times.
✗ Branch 1 not taken.
1017 if (autolock_)
110 {
111 1017 this->lock();
112 }
113
114 1017 bool read = false;
115 try
116 {
117
1/2
✓ Branch 2 taken 1017 times.
✗ Branch 3 not taken.
1017 read = memory_->read_serialized(serializable);
118 }
119 catch (const std::runtime_error &e)
120 {
121 if (autolock_)
122 {
123 memory_->unlock();
124 }
125
126 throw e;
127 }
128
129
2/2
✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 17 times.
1017 if (read)
130 {
131 1000 int id = serializable.get_id();
132 1000 memory_->write_serialized_id(id);
133 }
134
135
1/2
✓ Branch 0 taken 1017 times.
✗ Branch 1 not taken.
1017 if (autolock_)
136 {
137 1017 this->unlock();
138 }
139
140
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1017 return read;
141 }
142
143 template <class Serializable, int QUEUE_SIZE>
144 int Exchange_manager_consumer<Serializable, QUEUE_SIZE>::nb_char_read()
145 {
146 return memory_->nb_char_read();
147 }
148
149 template <class Serializable, int QUEUE_SIZE>
150 bool Exchange_manager_consumer<Serializable,
151 QUEUE_SIZE>::is_producer_queue_empty() const
152 {
153 return memory_->producer_queue_empty();
154 }
155
156 template <class Serializable, int QUEUE_SIZE>
157 bool Exchange_manager_consumer<Serializable,
158 QUEUE_SIZE>::is_consumer_queue_empty() const
159 {
160 return memory_->consumer_queue_empty();
161 }
162