Directory: | ./ |
---|---|
File: | include/shared_memory/shared_memory.hxx |
Date: | 2022-06-30 06:29:57 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 108 | 124 | 87.1% |
Branches: | 215 | 678 | 31.7% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * @file shared_memory.hxx | ||
3 | * @author Vincent Berenz | ||
4 | * @author Maximilien Naveau (maximilien.naveau@gmail.com) | ||
5 | * @license License BSD-3-Clause | ||
6 | * @copyright Copyright (c) 2019, New York University and Max Planck | ||
7 | * Gesellschaft. | ||
8 | * @date 2019-05-22 | ||
9 | * | ||
10 | * @brief This file implements the functions from shared_memory.hpp that | ||
11 | * encapsulate the use of the shared memory using the boost::interprocess | ||
12 | * package. usage: see demos and unit tests and documentation | ||
13 | */ | ||
14 | |||
15 | #pragma once | ||
16 | |||
17 | #include <shared_memory/shared_memory.hpp> | ||
18 | |||
19 | namespace shared_memory | ||
20 | { | ||
21 | // value will change with called | ||
22 | // to shared_memory::set_verbose | ||
23 | // used to turn off print console | ||
24 | // in code below | ||
25 | extern bool VERBOSE; | ||
26 | |||
27 | /*********************************************** | ||
28 | * Definition of the SharedMemorySegment class * | ||
29 | ***********************************************/ | ||
30 | template <typename ElemType> | ||
31 | 8848 | void SharedMemorySegment::get_object(const std::string& object_id, | |
32 | std::pair<ElemType*, std::size_t>& get_) | ||
33 | { | ||
34 | boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> | ||
35 |
4/10✓ Branch 1 taken 1030 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 11 taken 286 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 7531 times.
✗ Branch 17 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
|
17696 | lock(*mutex_); |
36 | |||
37 | // register_object(object_id, get_); | ||
38 | |||
39 |
4/10✓ Branch 1 taken 1030 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 286 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7531 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
8848 | bool registered = register_object_read_only<ElemType>(object_id); |
40 |
9/20✓ Branch 1 taken 1030 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1030 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✓ Branch 11 taken 286 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 286 times.
✓ Branch 16 taken 7531 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 7530 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
8848 | if (objects_[object_id].second != get_.second) |
41 | { | ||
42 |
1/10✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
1 | delete_object<ElemType>(object_id); |
43 | throw shared_memory::Unexpected_size_exception( | ||
44 |
2/20✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 29 taken 1 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 1 times.
✗ Branch 33 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
|
1 | segment_id_, object_id, objects_[object_id].second, get_.second); |
45 | } | ||
46 | |||
47 |
9/20✗ Branch 0 not taken.
✓ Branch 1 taken 1030 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 285 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 14 times.
✓ Branch 13 taken 7516 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 14 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
8847 | if (registered && VERBOSE) |
48 | { | ||
49 | ✗ | std::cout << "shared_memory::SharedMemoryObject | registration of " | |
50 | ✗ | << object_id << " of size " << get_.second << std::endl; | |
51 | } | ||
52 | |||
53 |
4/10✓ Branch 1 taken 1030 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 286 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7530 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
8847 | ElemType* shared_data = static_cast<ElemType*>(objects_[object_id].first); |
54 |
4/10✓ Branch 1 taken 1030 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 286 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7530 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
8847 | std::size_t shared_data_size = objects_[object_id].second; |
55 |
8/10✓ Branch 0 taken 1030 times.
✓ Branch 1 taken 1030 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 286 times.
✓ Branch 5 taken 286 times.
✓ Branch 6 taken 30097 times.
✓ Branch 7 taken 7530 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
40261 | for (std::size_t i = 0; i < shared_data_size; ++i) |
56 | { | ||
57 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
31414 | get_.first[i] = shared_data[i]; |
58 | } | ||
59 | 8847 | } | |
60 | |||
61 | template <typename ElemType> | ||
62 | 10097 | void SharedMemorySegment::set_object( | |
63 | const std::string& object_id, | ||
64 | const std::pair<const ElemType*, std::size_t>& set_) | ||
65 | { | ||
66 | boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> | ||
67 |
4/10✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
✓ Branch 11 taken 36 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 10040 times.
✗ Branch 17 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
|
20194 | lock(*mutex_); |
68 | |||
69 |
6/10✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 36 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 10040 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
10097 | bool registered = register_object(object_id, set_); |
70 | |||
71 |
11/20✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 12 times.
✓ Branch 8 taken 16 times.
✓ Branch 9 taken 20 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 16 times.
✓ Branch 12 taken 30 times.
✓ Branch 13 taken 10010 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 30 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
10095 | if (registered && VERBOSE) |
72 | { | ||
73 | ✗ | std::cout << "shared_memory::SharedMemoryObject | registration of " | |
74 | ✗ | << object_id << " of size " << objects_[object_id].second | |
75 | << std::endl; | ||
76 | } | ||
77 | |||
78 |
4/10✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 36 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 10040 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
10095 | ElemType* shared_data = static_cast<ElemType*>(objects_[object_id].first); |
79 |
4/10✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 36 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 10040 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
10095 | std::size_t shared_data_size = objects_[object_id].second; |
80 |
8/10✓ Branch 0 taken 69 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 69 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 40098 times.
✓ Branch 7 taken 10040 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
50345 | for (std::size_t i = 0; i < shared_data_size; ++i) |
81 | { | ||
82 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
40250 | shared_data[i] = set_.first[i]; |
83 | } | ||
84 | 10095 | } | |
85 | |||
86 | template <typename ElemType> | ||
87 | 10097 | bool SharedMemorySegment::register_object( | |
88 | const std::string& object_id, const std::pair<ElemType*, std::size_t>& obj_) | ||
89 | { | ||
90 |
7/10✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 13 times.
✓ Branch 7 taken 20 times.
✓ Branch 8 taken 16 times.
✓ Branch 10 taken 10010 times.
✓ Branch 11 taken 30 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
10097 | if (is_object_registered(object_id)) |
91 | { | ||
92 | 10032 | return false; | |
93 | } | ||
94 | 65 | std::size_t obj_size = 0; | |
95 | 65 | typename std::remove_const<ElemType>::type* obj_ptr = nullptr; | |
96 | |||
97 |
6/10✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 30 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
65 | obj_ptr = |
98 | segment_manager_ | ||
99 | .find_or_construct<typename std::remove_const<ElemType>::type>( | ||
100 |
4/10✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 10 taken 13 times.
✗ Branch 11 not taken.
✓ Branch 17 taken 16 times.
✗ Branch 18 not taken.
✓ Branch 24 taken 30 times.
✗ Branch 25 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
|
130 | object_id.c_str())[obj_.second](); |
101 | 63 | obj_size = obj_.second; | |
102 | |||
103 |
4/10✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
✓ Branch 17 taken 30 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
63 | objects_[object_id] = std::pair<void*, std::size_t>(); |
104 | 63 | objects_[object_id].first = static_cast<void*>(obj_ptr); | |
105 | 63 | objects_[object_id].second = obj_size; | |
106 | |||
107 | 63 | return true; | |
108 | } | ||
109 | |||
110 | template <typename ElemType> | ||
111 | 8851 | bool SharedMemorySegment::register_object_read_only( | |
112 | const std::string& object_id) | ||
113 | { | ||
114 |
11/20✓ Branch 1 taken 1033 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1032 times.
✓ Branch 4 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✓ Branch 11 taken 286 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 285 times.
✓ Branch 14 taken 1 times.
✓ Branch 16 taken 7531 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 7516 times.
✓ Branch 19 taken 15 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
8851 | if (is_object_registered(object_id)) |
115 | { | ||
116 | 8833 | return false; | |
117 | } | ||
118 | |||
119 | 18 | std::size_t obj_size = 0; | |
120 | 18 | typename std::remove_const<ElemType>::type* obj_ptr = nullptr; | |
121 | |||
122 | std::pair<typename std::remove_const<ElemType>::type*, std::size_t> | ||
123 |
4/10✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 18 taken 15 times.
✗ Branch 19 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
18 | obj_pair = |
124 | segment_manager_.find<typename std::remove_const<ElemType>::type>( | ||
125 | object_id.c_str()); | ||
126 | 18 | obj_ptr = obj_pair.first; | |
127 | 18 | obj_size = obj_pair.second; | |
128 | |||
129 |
4/10✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 17 taken 15 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
18 | objects_[object_id] = std::pair<void*, std::size_t>(); |
130 |
4/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 15 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
18 | objects_[object_id].first = static_cast<void*>(obj_ptr); |
131 |
4/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 15 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
18 | objects_[object_id].second = obj_size; |
132 | |||
133 | 18 | return true; | |
134 | } | ||
135 | |||
136 | template <typename ElemType> | ||
137 | 1 | void SharedMemorySegment::delete_object(const std::string& object_id) | |
138 | { | ||
139 | try | ||
140 | { | ||
141 |
2/20✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
1 | if (objects_.count(object_id) != 0) |
142 | { | ||
143 |
1/10✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
1 | objects_.erase(object_id); |
144 | } | ||
145 |
1/20✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
|
1 | segment_manager_.destroy<ElemType>(object_id.c_str()); |
146 | } | ||
147 | ✗ | catch (const boost::interprocess::interprocess_exception&) | |
148 | { | ||
149 | ✗ | return; | |
150 | } | ||
151 | } | ||
152 | |||
153 | /************************************************* | ||
154 | * Definition of all segment management function * | ||
155 | *************************************************/ | ||
156 | |||
157 | /** | ||
158 | * @brief SegmentMap typedef is a simple short cut to the GLOBAL_SHM_SEGMENTS | ||
159 | * type. | ||
160 | */ | ||
161 | typedef std::map<std::string, std::unique_ptr<SharedMemorySegment> > SegmentMap; | ||
162 | |||
163 | /** | ||
164 | * @brief GLOBAL_SHARED_MEMORY_SEGMENT is global variable that acts as a | ||
165 | * a shared memory manager. | ||
166 | * | ||
167 | * The use of the std::unique_ptr allows to delete the object and re-create | ||
168 | * at will. | ||
169 | */ | ||
170 | 378 | static SegmentMap GLOBAL_SHM_SEGMENTS; | |
171 | |||
172 | template <typename ElemType> | ||
173 | bool delete_object(const std::string& segment_id, const std::string& object_id) | ||
174 | { | ||
175 | try | ||
176 | { | ||
177 | SharedMemorySegment& segment = get_segment(segment_id); | ||
178 | segment.delete_object<ElemType>(object_id); | ||
179 | } | ||
180 | catch (const boost::interprocess::interprocess_exception&) | ||
181 | { | ||
182 | return false; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | /*********************************** | ||
187 | * Definition of all set functions * | ||
188 | ***********************************/ | ||
189 | |||
190 | template <typename ElemType> | ||
191 | 59 | void set(const std::string& segment_id, | |
192 | const std::string& object_id, | ||
193 | const ElemType& set_) | ||
194 | { | ||
195 | try | ||
196 | { | ||
197 |
4/10✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 34 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
59 | SharedMemorySegment& segment = get_segment(segment_id); |
198 | 59 | std::pair<const ElemType*, std::size_t> set_ref; | |
199 | 59 | set_ref.first = &set_; | |
200 | 59 | set_ref.second = 1; | |
201 |
4/10✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 34 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
59 | segment.set_object<ElemType>(object_id, set_ref); |
202 | } | ||
203 | ✗ | catch (const boost::interprocess::bad_alloc&) | |
204 | { | ||
205 | ✗ | throw shared_memory::Allocation_exception(segment_id, object_id); | |
206 | } | ||
207 |
0/10✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
59 | } |
208 | |||
209 | template <typename ElemType> | ||
210 | 10038 | void set(const std::string& segment_id, | |
211 | const std::string& object_id, | ||
212 | const ElemType* set_, | ||
213 | const std::size_t size) | ||
214 | { | ||
215 | try | ||
216 | { | ||
217 |
3/6✓ Branch 1 taken 10026 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
|
10038 | SharedMemorySegment& segment = get_segment(segment_id); |
218 | 10038 | std::pair<const ElemType*, std::size_t> set_ref; | |
219 | 10038 | set_ref.first = set_; | |
220 | 10038 | set_ref.second = size; | |
221 |
4/6✓ Branch 1 taken 10025 times.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
|
10038 | segment.set_object<ElemType>(object_id, set_ref); |
222 | } | ||
223 | 4 | catch (const boost::interprocess::bad_alloc&) | |
224 | { | ||
225 |
2/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
2 | throw shared_memory::Allocation_exception(segment_id, object_id); |
226 | } | ||
227 |
2/6✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
10036 | } |
228 | |||
229 | template <typename VectorType, typename ElemType> | ||
230 | void set(const std::string& segment_id, | ||
231 | const std::string& object_id, | ||
232 | const VectorType& set_) | ||
233 | { | ||
234 | set<ElemType>(segment_id, object_id, set_.data(), set_.size()); | ||
235 | } | ||
236 | |||
237 | template <typename ElemType> | ||
238 | 7 | void set(const std::string& segment_id, | |
239 | const std::string& object_id, | ||
240 | const std::vector<ElemType>& set_) | ||
241 | { | ||
242 | 7 | set<ElemType>(segment_id, object_id, set_.data(), set_.size()); | |
243 | 5 | } | |
244 | |||
245 | template <typename ElemType> | ||
246 | 2 | void set(const std::string& segment_id, | |
247 | const std::string& object_id, | ||
248 | const Eigen::Matrix<ElemType, Eigen::Dynamic, 1>& set_) | ||
249 | { | ||
250 | 2 | set<ElemType>(segment_id, object_id, set_.data(), set_.size()); | |
251 | 2 | } | |
252 | |||
253 | template <typename FirstType, typename SecondType> | ||
254 | void set(const std::string& segment_id, | ||
255 | const std::string& object_id, | ||
256 | const std::pair<FirstType, SecondType>& set_) | ||
257 | { | ||
258 | set<FirstType>(segment_id, object_id + "_first", set_.first); | ||
259 | set<SecondType>(segment_id, object_id + "_second", set_.second); | ||
260 | } | ||
261 | |||
262 | template <typename KeyType, typename ValueType> | ||
263 | 4 | void set(const std::string& segment_id, | |
264 | const std::string& object_id, | ||
265 | const std::map<KeyType, ValueType>& set_) | ||
266 | { | ||
267 | try | ||
268 | { | ||
269 | 4 | int i = 0; | |
270 | 12 | for (typename std::map<KeyType, ValueType>::const_iterator map_it = | |
271 | set_.begin(); | ||
272 |
8/8✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 1 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 1 times.
|
12 | map_it != set_.end(); |
273 | ++map_it) | ||
274 | { | ||
275 |
16/40✓ 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 18 not taken.
✗ Branch 19 not taken.
✓ Branch 22 taken 2 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 2 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 2 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 2 times.
✗ Branch 32 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✓ Branch 43 taken 2 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 2 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 2 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 2 times.
✗ Branch 53 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✓ Branch 64 taken 2 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 2 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 2 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 2 times.
✗ Branch 74 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
|
8 | set(segment_id, |
276 | object_id + "_" + std::to_string(i), | ||
277 | 8 | map_it->second); | |
278 | 8 | ++i; | |
279 | } | ||
280 | } | ||
281 | ✗ | catch (const boost::interprocess::bad_alloc&) | |
282 | { | ||
283 | ✗ | throw shared_memory::Allocation_exception(segment_id, object_id); | |
284 | } | ||
285 | 4 | } | |
286 | |||
287 | /*********************************** | ||
288 | * Definition of all get functions * | ||
289 | ***********************************/ | ||
290 | |||
291 | template <typename ElemType> | ||
292 | 1323 | void get(const std::string& segment_id, | |
293 | const std::string& object_id, | ||
294 | ElemType& get_, | ||
295 | bool create) | ||
296 | { | ||
297 | try | ||
298 | { | ||
299 |
5/10✓ Branch 1 taken 1030 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 286 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
1323 | SharedMemorySegment& segment = get_segment(segment_id, false, create); |
300 | 1322 | std::pair<ElemType*, std::size_t> get_ref; | |
301 | 1322 | get_ref.first = &get_; | |
302 | 1322 | get_ref.second = 1; | |
303 |
4/10✓ Branch 1 taken 1030 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 286 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
1322 | segment.get_object<ElemType>(object_id, get_ref); |
304 | } | ||
305 | ✗ | catch (const boost::interprocess::bad_alloc&) | |
306 | { | ||
307 | ✗ | throw shared_memory::Allocation_exception(segment_id, object_id); | |
308 | } | ||
309 |
1/10✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
1322 | } |
310 | |||
311 | template <typename ElemType> | ||
312 | 7526 | void get(const std::string& segment_id, | |
313 | const std::string& object_id, | ||
314 | ElemType* get_, | ||
315 | const std::size_t expected_size, | ||
316 | bool create) | ||
317 | { | ||
318 | try | ||
319 | { | ||
320 |
1/2✓ Branch 1 taken 7526 times.
✗ Branch 2 not taken.
|
7526 | SharedMemorySegment& segment = get_segment(segment_id, false, create); |
321 | 7526 | std::pair<ElemType*, std::size_t> get_ref; | |
322 | 7526 | get_ref.first = get_; | |
323 | 7526 | get_ref.second = expected_size; | |
324 |
2/2✓ Branch 1 taken 7525 times.
✓ Branch 2 taken 1 times.
|
7526 | segment.get_object<ElemType>(object_id, get_ref); |
325 | } | ||
326 | ✗ | catch (const boost::interprocess::bad_alloc&) | |
327 | { | ||
328 | ✗ | throw shared_memory::Allocation_exception(segment_id, object_id); | |
329 | } | ||
330 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
7525 | } |
331 | |||
332 | template <typename ElemType> | ||
333 | 4 | void get(const std::string& segment_id, | |
334 | const std::string& object_id, | ||
335 | std::vector<ElemType>& get_, | ||
336 | bool create) | ||
337 | { | ||
338 | 4 | get<ElemType>(segment_id, object_id, &(get_[0]), get_.size(), create); | |
339 | 3 | } | |
340 | |||
341 | template <typename ElemType> | ||
342 | 3 | void get(const std::string& segment_id, | |
343 | const std::string& object_id, | ||
344 | Eigen::Matrix<ElemType, Eigen::Dynamic, 1>& get_, | ||
345 | bool create) | ||
346 | { | ||
347 | 3 | get(segment_id, object_id, get_.data(), get_.size(), create); | |
348 | 3 | } | |
349 | |||
350 | template <typename FirstType, typename SecondType> | ||
351 | void get(const std::string& segment_id, | ||
352 | const std::string& object_id, | ||
353 | std::pair<FirstType, SecondType>& get_, | ||
354 | bool create) | ||
355 | { | ||
356 | get<FirstType>(segment_id, object_id + "_first", get_.first, create); | ||
357 | get<SecondType>(segment_id, object_id + "_second", get_.second, create); | ||
358 | } | ||
359 | |||
360 | template <typename KeyType, typename ValueType> | ||
361 | 4 | void get(const std::string& segment_id, | |
362 | const std::string& object_id, | ||
363 | std::map<KeyType, ValueType>& get_, | ||
364 | bool create) | ||
365 | { | ||
366 | try | ||
367 | { | ||
368 | 4 | int i = 0; | |
369 | 12 | for (typename std::map<KeyType, ValueType>::iterator map_it = | |
370 | get_.begin(); | ||
371 |
8/8✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 1 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 1 times.
|
12 | map_it != get_.end(); |
372 | ++map_it) | ||
373 | { | ||
374 |
16/40✓ 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 18 not taken.
✗ Branch 19 not taken.
✓ Branch 22 taken 2 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 2 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 2 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 2 times.
✗ Branch 32 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✓ Branch 43 taken 2 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 2 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 2 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 2 times.
✗ Branch 53 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✓ Branch 64 taken 2 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 2 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 2 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 2 times.
✗ Branch 74 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
|
16 | get(segment_id, |
375 | object_id + "_" + std::to_string(i), | ||
376 | 8 | map_it->second, | |
377 | create); | ||
378 | 8 | ++i; | |
379 | } | ||
380 | } | ||
381 | ✗ | catch (const boost::interprocess::bad_alloc&) | |
382 | { | ||
383 | ✗ | throw shared_memory::Allocation_exception(segment_id, object_id); | |
384 | } | ||
385 | 4 | } | |
386 | |||
387 | } // namespace shared_memory | ||
388 |