iceoryx_hoofs 2.0.3
variant_queue.hpp
1// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2020 - 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_HOOFS_CXX_VARIANT_QUEUE_HPP
18#define IOX_HOOFS_CXX_VARIANT_QUEUE_HPP
19
20#include "iceoryx_hoofs/concurrent/resizeable_lockfree_queue.hpp"
21#include "iceoryx_hoofs/cxx/expected.hpp"
22#include "iceoryx_hoofs/cxx/optional.hpp"
23#include "iceoryx_hoofs/cxx/variant.hpp"
24#include "iceoryx_hoofs/internal/concurrent/fifo.hpp"
25#include "iceoryx_hoofs/internal/concurrent/sofi.hpp"
26
27#include <cstdint>
28
29namespace iox
30{
31namespace cxx
32{
39enum class VariantQueueTypes : uint64_t
40{
41 FiFo_SingleProducerSingleConsumer = 0,
42 SoFi_SingleProducerSingleConsumer = 1,
43 FiFo_MultiProducerSingleConsumer = 2,
44 SoFi_MultiProducerSingleConsumer = 3
45};
46
47// remark: we need to consider to support the non-resizable queue as well
48// since it should have performance benefits if resize is not actually needed
49// for now we just use the most general variant, which allows resizing
50
69template <typename ValueType, uint64_t Capacity>
71{
72 public:
74 concurrent::SoFi<ValueType, Capacity>,
77
80 VariantQueue(const VariantQueueTypes type) noexcept;
81
87 optional<ValueType> push(const ValueType& value) noexcept;
88
93
95 bool empty() const noexcept;
96
100 uint64_t size() noexcept;
101
110 bool setCapacity(const uint64_t newCapacity) noexcept;
111
114 uint64_t capacity() const noexcept;
115
125
126 private:
127 VariantQueueTypes m_type;
128 fifo_t m_fifo;
129};
130} // namespace cxx
131} // namespace iox
132
133#include "iceoryx_hoofs/internal/cxx/variant_queue.inl"
134
135#endif // IOX_HOOFS_CXX_VARIANT_QUEUE_HPP
implements a lock free queue (i.e. container with FIFO order) of elements of type T with a maximum ca...
Definition: resizeable_lockfree_queue.hpp:48
wrapper of multiple fifo's
Definition: variant_queue.hpp:71
optional< ValueType > pop() noexcept
pops an element from the fifo
fifo_t & getUnderlyingFiFo() noexcept
returns reference to the underlying fifo
uint64_t capacity() const noexcept
get the capacity of the queue.
optional< ValueType > push(const ValueType &value) noexcept
pushs an element into the fifo
bool setCapacity(const uint64_t newCapacity) noexcept
set the capacity of the queue
VariantQueue(const VariantQueueTypes type) noexcept
Constructor of a VariantQueue.
uint64_t size() noexcept
get the current size of the queue. Caution, another thread can have changed the size just after readi...
bool empty() const noexcept
returns true if empty otherwise true
Optional implementation from the C++17 standard with C++11. The interface is analog to the C++17 stan...
Definition: optional.hpp:69
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29