17 #ifndef IOX_UTILS_LOCKFREE_QUEUE_INDEX_QUEUE_HPP
18 #define IOX_UTILS_LOCKFREE_QUEUE_INDEX_QUEUE_HPP
20 #include "iceoryx_utils/cxx/optional.hpp"
21 #include "iceoryx_utils/internal/concurrent/lockfree_queue/buffer.hpp"
22 #include "iceoryx_utils/internal/concurrent/lockfree_queue/cyclic_index.hpp"
25 #include <type_traits>
31 template <
typename ElementType, u
int64_t Capacity>
34 template <
typename ElementType, u
int64_t Capacity>
35 class ResizeableLockFreeQueue;
38 template <u
int64_t Capacity,
typename ValueType = u
int64_t>
42 static_assert(std::is_unsigned<ValueType>::value,
"ValueType must be an unsigned integral type");
44 using value_t = ValueType;
55 static constexpr ConstructEmpty_t ConstructEmpty{};
57 ~IndexQueue() =
default;
58 IndexQueue(
const IndexQueue&) =
delete;
59 IndexQueue(IndexQueue&&) =
delete;
60 IndexQueue& operator=(
const IndexQueue&) =
delete;
61 IndexQueue& operator=(IndexQueue&&) =
delete;
64 IndexQueue(ConstructEmpty_t = ConstructEmpty) noexcept;
67 IndexQueue(ConstructFull_t) noexcept;
72 constexpr uint64_t
capacity() const noexcept;
79 bool empty() const noexcept;
86 void push(const ValueType index) noexcept;
90 cxx::optional<ValueType>
pop() noexcept;
94 cxx::optional<ValueType>
popIfFull() noexcept;
103 template <typename ElementType, uint64_t Cap>
104 friend class LockFreeQueue;
106 template <typename ElementType, uint64_t Cap>
107 friend class ResizeableLockFreeQueue;
111 using Index = CyclicIndex<Capacity>;
112 using Cell = std::atomic<Index>;
118 Cell m_cells[Capacity];
120 std::atomic<Index> m_readPosition;
121 std::atomic<Index> m_writePosition;
127 Index loadvalueAt(const Index& position, std::memory_order memoryOrder = std::memory_order_relaxed) const;
132 bool pop(ValueType& index) noexcept;
143 bool popIfFull(ValueType& index) noexcept;
148 #include "index_queue.inl"
lockfree queue capable of storing indices 0,1,... Capacity-1
Definition: index_queue.hpp:40
cxx::optional< ValueType > popIfFull() noexcept
pop an index from the queue in FIFO order if the queue is full
Definition: index_queue.inl:288
cxx::optional< ValueType > pop() noexcept
pop an index from the queue in FIFO order if the queue not empty
Definition: index_queue.inl:277
void push(const ValueType index) noexcept
push index into the queue in FIFO order
Definition: index_queue.inl:50
constexpr uint64_t capacity() const noexcept
get the capacity of the IndexQueue
Definition: index_queue.inl:44
bool empty() const noexcept
check whether the queue is empty
Definition: index_queue.inl:310
cxx::optional< ValueType > popIfSizeIsAtLeast(uint64_t size) noexcept
pop an index from the queue in FIFO order if the queue contains at least a specified number number of...
Definition: index_queue.inl:299
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28
Definition: index_queue.hpp:51
Definition: index_queue.hpp:47