iceoryx_doc  1.0.1
used_chunk_list.hpp
1 // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 #ifndef IOX_POSH_POPO_USED_CHUNK_LIST_HPP
18 #define IOX_POSH_POPO_USED_CHUNK_LIST_HPP
19 
20 #include "iceoryx_posh/internal/mepoo/shared_chunk.hpp"
21 #include "iceoryx_posh/internal/mepoo/shm_safe_unmanaged_chunk.hpp"
22 #include "iceoryx_posh/mepoo/chunk_header.hpp"
23 
24 #include <atomic>
25 #include <cstdint>
26 
27 namespace iox
28 {
29 namespace popo
30 {
41 template <uint32_t Capacity>
43 {
44  static_assert(Capacity > 0, "UsedChunkList Capacity must be larger than 0!");
45 
46  public:
48  UsedChunkList() noexcept;
49 
54  bool insert(mepoo::SharedChunk chunk) noexcept;
55 
61  bool remove(const mepoo::ChunkHeader* chunkHeader, mepoo::SharedChunk& chunk) noexcept;
62 
66  void cleanup() noexcept;
67 
68  private:
69  void init() noexcept;
70 
71  private:
72  static constexpr uint32_t INVALID_INDEX{Capacity};
73 
75  static constexpr DataElement_t DATA_ELEMENT_LOGICAL_NULLPTR{};
76 
77  private:
78  std::atomic_flag m_synchronizer = ATOMIC_FLAG_INIT;
79  uint32_t m_usedListHead{INVALID_INDEX};
80  uint32_t m_freeListHead{0u};
81  uint32_t m_listIndices[Capacity];
82  DataElement_t m_listData[Capacity];
83 };
84 
85 } // namespace popo
86 } // namespace iox
87 
88 #include "used_chunk_list.inl"
89 
90 #endif // IOX_POSH_POPO_USED_CHUNK_LIST_HPP
WARNING: SharedChunk is not thread safe! Don't share SharedChunk objects between threads!...
Definition: shared_chunk.hpp:35
This class to safely store a chunk in shared memory. To be able to do so, torn writes/reads need to p...
Definition: shm_safe_unmanaged_chunk.hpp:31
This class is used to keep track of the chunks currently in use by the application....
Definition: used_chunk_list.hpp:43
bool remove(const mepoo::ChunkHeader *chunkHeader, mepoo::SharedChunk &chunk) noexcept
Removes a chunk from the list.
Definition: used_chunk_list.inl:67
bool insert(mepoo::SharedChunk chunk) noexcept
Inserts a SharedChunk into the list.
Definition: used_chunk_list.inl:39
void cleanup() noexcept
Cleans up all the remaining chunks from the list.
Definition: used_chunk_list.inl:106
UsedChunkList() noexcept
Constructs a default UsedChunkList.
Definition: used_chunk_list.inl:29
Definition: service_description.hpp:29
Definition: chunk_header.hpp:42