iceoryx_hoofs/cxx/variant_queue.hpp🔗
Namespaces🔗
Name |
---|
iox building block to easily create free function for logging in a library context |
iox::cxx |
Classes🔗
Name | |
---|---|
class | iox::cxx::VariantQueue wrapper of multiple fifo's |
Source code🔗
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CXX_VARIANT_QUEUE_HPP
#define IOX_HOOFS_CXX_VARIANT_QUEUE_HPP
#include "iceoryx_hoofs/concurrent/resizeable_lockfree_queue.hpp"
#include "iceoryx_hoofs/cxx/expected.hpp"
#include "iceoryx_hoofs/cxx/optional.hpp"
#include "iceoryx_hoofs/cxx/variant.hpp"
#include "iceoryx_hoofs/internal/concurrent/fifo.hpp"
#include "iceoryx_hoofs/internal/concurrent/sofi.hpp"
#include <cstdint>
namespace iox
{
namespace cxx
{
enum class VariantQueueTypes : uint64_t
{
FiFo_SingleProducerSingleConsumer = 0,
SoFi_SingleProducerSingleConsumer = 1,
FiFo_MultiProducerSingleConsumer = 2,
SoFi_MultiProducerSingleConsumer = 3
};
// remark: we need to consider to support the non-resizable queue as well
// since it should have performance benefits if resize is not actually needed
// for now we just use the most general variant, which allows resizing
template <typename ValueType, uint64_t Capacity>
class VariantQueue
{
public:
using fifo_t = variant<concurrent::FiFo<ValueType, Capacity>,
concurrent::SoFi<ValueType, Capacity>,
concurrent::ResizeableLockFreeQueue<ValueType, Capacity>,
concurrent::ResizeableLockFreeQueue<ValueType, Capacity>>;
VariantQueue(const VariantQueueTypes type) noexcept;
optional<ValueType> push(const ValueType& value) noexcept;
optional<ValueType> pop() noexcept;
bool empty() const noexcept;
uint64_t size() noexcept;
bool setCapacity(const uint64_t newCapacity) noexcept;
uint64_t capacity() const noexcept;
fifo_t& getUnderlyingFiFo() noexcept;
private:
VariantQueueTypes m_type;
fifo_t m_fifo;
};
} // namespace cxx
} // namespace iox
#include "iceoryx_hoofs/internal/cxx/variant_queue.inl"
#endif // IOX_HOOFS_CXX_VARIANT_QUEUE_HPP
Updated on 18 December 2023 at 13:11:42 CET