Directory: | ./ |
---|---|
File: | include/shared_memory/array_fundamental_array.hxx |
Date: | 2022-06-30 06:29:57 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 29 | 31 | 93.5% |
Branches: | 14 | 28 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2019 Max Planck Gesellschaft | ||
2 | // Author : Vincent Berenz | ||
3 | |||
4 | template <typename T, int SIZE> | ||
5 | 2 | void array<T, SIZE>::init(FUNDAMENTAL_ARRAY) | |
6 | { | ||
7 | 2 | this->total_size_ = size_ * SIZE; | |
8 | |||
9 | 2 | uint segment_size = get_segment_size(this->total_size_, sizeof(T)); | |
10 | |||
11 |
2/4✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
2 | segment_manager_ = boost::interprocess::managed_shared_memory( |
12 | boost::interprocess::open_or_create, segment_id_.c_str(), segment_size); | ||
13 | 2 | this->shared_ = segment_manager_.find_or_construct<T>( | |
14 |
2/4✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
4 | segment_id_.c_str())[this->total_size_](); |
15 | 2 | } | |
16 | |||
17 | template <typename T, int SIZE> | ||
18 | 102 | void array<T, SIZE>::set(uint index, const T& t, FUNDAMENTAL_ARRAY) | |
19 | { | ||
20 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 102 times.
|
102 | if (index >= this->size_) |
21 | { | ||
22 | ✗ | throw std::runtime_error("invalid index"); | |
23 | } | ||
24 |
1/2✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
|
102 | if (multiprocess_safe_) |
25 | { | ||
26 | 102 | mutex_.lock(); | |
27 | } | ||
28 | 102 | uint abs_index = index * SIZE; | |
29 | 102 | uint c = 0; | |
30 |
2/2✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 102 times.
|
1122 | for (uint i = abs_index; i < abs_index + SIZE; i++) |
31 | { | ||
32 | 1020 | this->shared_[i] = (&t)[c++]; | |
33 | } | ||
34 |
1/2✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
|
102 | if (multiprocess_safe_) |
35 | { | ||
36 | 102 | mutex_.unlock(); | |
37 | } | ||
38 | 102 | } | |
39 | |||
40 | template <typename T, int SIZE> | ||
41 | 202 | void array<T, SIZE>::get(uint index, T& t, FUNDAMENTAL_ARRAY) | |
42 | { | ||
43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 202 times.
|
202 | if (index > size_) |
44 | { | ||
45 | ✗ | throw std::runtime_error("invalid index"); | |
46 | } | ||
47 |
1/2✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
|
202 | if (multiprocess_safe_) |
48 | { | ||
49 | 202 | mutex_.lock(); | |
50 | } | ||
51 | 202 | uint abs_index = index * SIZE; | |
52 | 202 | uint c = 0; | |
53 |
2/2✓ Branch 0 taken 2020 times.
✓ Branch 1 taken 202 times.
|
2222 | for (uint i = abs_index; i < abs_index + SIZE; i++) |
54 | { | ||
55 | 2020 | (&t)[c++] = this->shared_[i]; | |
56 | } | ||
57 |
1/2✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
|
202 | if (multiprocess_safe_) |
58 | { | ||
59 | 202 | mutex_.unlock(); | |
60 | } | ||
61 | 202 | } | |
62 | |||
63 | template <typename T, int SIZE> | ||
64 | std::string array<T, SIZE>::get_serialized(uint index, FUNDAMENTAL_ARRAY) | ||
65 | { | ||
66 | throw std::logic_error( | ||
67 | "function not implemented for shared memory arrays encapsulating array " | ||
68 | "of fundamental types"); | ||
69 | } | ||
70 |