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