iceoryx_doc  1.0.1
typed_mem_pool.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_MEPOO_TYPED_MEM_POOL_HPP
18 #define IOX_POSH_MEPOO_TYPED_MEM_POOL_HPP
19 
20 #include "iceoryx_posh/iceoryx_posh_types.hpp"
21 #include "iceoryx_posh/internal/mepoo/chunk_management.hpp"
22 #include "iceoryx_posh/internal/mepoo/mem_pool.hpp"
23 #include "iceoryx_posh/internal/mepoo/memory_manager.hpp"
24 #include "iceoryx_posh/internal/mepoo/shared_pointer.hpp"
25 #include "iceoryx_utils/cxx/expected.hpp"
26 #include "iceoryx_utils/cxx/helplets.hpp"
27 #include "iceoryx_utils/cxx/optional.hpp"
28 #include "iceoryx_utils/cxx/variant.hpp"
29 #include "iceoryx_utils/error_handling/error_handling.hpp"
30 
31 #include <algorithm>
32 
33 namespace iox
34 {
35 namespace mepoo
36 {
37 enum class TypedMemPoolError
38 {
39  INVALID_STATE,
40  OutOfChunks,
41  FatalErrorReachedInconsistentState
42 };
43 
44 template <typename T>
46 {
47  public:
48  TypedMemPool(const cxx::greater_or_equal<uint32_t, 1> numberOfChunks,
49  posix::Allocator& managementAllocator,
50  posix::Allocator& chunkMemoryAllocator) noexcept;
51 
52  TypedMemPool(const TypedMemPool&) = delete;
53  TypedMemPool(TypedMemPool&&) = delete;
54  TypedMemPool& operator=(const TypedMemPool&) = delete;
55  TypedMemPool& operator=(TypedMemPool&&) = delete;
56 
57  template <typename... Targs>
58  cxx::expected<SharedPointer<T>, TypedMemPoolError> createObject(Targs&&... args) noexcept;
59  template <typename ErrorType, typename... Targs>
60  cxx::expected<SharedPointer<T>, cxx::variant<TypedMemPoolError, ErrorType>>
61  createObjectWithCreationPattern(Targs&&... args) noexcept;
62  uint32_t getChunkCount() const noexcept;
63  uint32_t getUsedChunks() const noexcept;
64 
65  static uint64_t requiredManagementMemorySize(const uint64_t f_numberOfChunks) noexcept;
66  static uint64_t requiredChunkMemorySize(const uint64_t f_numberOfChunks) noexcept;
67  static uint64_t requiredFullMemorySize(const uint64_t f_numberOfChunks) noexcept;
68 
69  private:
70  static uint64_t requiredChunkSize() noexcept;
71  cxx::expected<ChunkManagement*, TypedMemPoolError> acquireChunkManagementPointer() noexcept;
72 
73  private:
74  MemPool m_memPool;
75  MemPool m_chunkManagementPool;
76 };
77 } // namespace mepoo
78 } // namespace iox
79 
80 
81 #include "typed_mem_pool.inl"
82 
83 #endif // IOX_POSH_MEPOO_TYPED_MEM_POOL_HPP
Definition: mem_pool.hpp:48
Definition: typed_mem_pool.hpp:46
Definition: service_description.hpp:29