Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1391 Move 'FiFo' to new location
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Dec 22, 2023
1 parent 6dbf9d8 commit fd1f97b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 31 deletions.
4 changes: 2 additions & 2 deletions iceoryx_hoofs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an

| class | internal | description |
|:----------------------------------:|:--------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`FiFo` | i | Single producer, single consumer lock-free FiFo |
|`SpscFifo` | i | Single producer, single consumer lock-free FiFo |
|`LockfreeQueue` | | Multi producer, multi consumer lock-free FiFo with ringbuffer like overflow handling |
|`MpmcLoFFLi` | i | Lock-free LIFO based index manager (lock-free free list). One building block of our memory manager. After construction it contains the indices {0 ... n} which you can acquire and release. |
|`SoFi` | i | Single producer, single consumer lock-free safely overflowing FiFo (SoFi). |
Expand All @@ -111,7 +111,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an

| Data Structure | Shared Memory usable | Thread-Safe | Lock-Free | Concurrent Producers : Consumers | Bounded Capacity | Data Type Restriction | Use Case |
|--------------------------|-----------------------|-------------|-----------|----------------------------------|------------------|-----------------------|-------------------------------------------------------------------------------------------------------------------------|
|`FiFo` | Yes | Yes | Yes | 1:1 | Yes | Copyable | FIFO Data transfer |
|`SpscFifo` | Yes | Yes | Yes | 1:1 | Yes | Copyable | FIFO Data transfer |
|`LockfreeQueue` | Yes | Yes | Yes | n:m | Yes | Copyable or Movable | lock-free transfer of arbitrary data between multiple contexts in FIFO order with overflow handling (ringbuffer) |
|`MpmcLoFFLi` | Yes | Yes | Yes | n:m | Yes | int32 | manage memory access, LIFO order |
|`SoFi` | Yes | Yes | Yes | 1:1 | Yes | Trivially Copyable | lock-free transfer of small data (e.g. pointers) between two contexts in FIFO order with overflow handling (ringbuffer) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CONCURRENT_FIFO_HPP
#define IOX_HOOFS_CONCURRENT_FIFO_HPP

#ifndef IOX_HOOFS_CONCURRENT_BUFFER_SPSC_FIFO_HPP
#define IOX_HOOFS_CONCURRENT_BUFFER_SPSC_FIFO_HPP

#include "iox/optional.hpp"
#include "iox/uninitialized_array.hpp"
Expand All @@ -28,7 +29,7 @@ namespace concurrent
{
/// @brief single pusher single pop'er thread safe fifo
template <typename ValueType, uint64_t Capacity>
class FiFo
class SpscFifo
{
public:
/// @brief pushes a value into the fifo
Expand Down Expand Up @@ -62,6 +63,6 @@ class FiFo
} // namespace concurrent
} // namespace iox

#include "iceoryx_hoofs/internal/concurrent/fifo.inl"
#include "iox/detail/spsc_fifo.inl"

#endif // IOX_HOOFS_CONCURRENT_FIFO_HPP
#endif // IOX_HOOFS_CONCURRENT_BUFFER_SPSC_FIFO_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CONCURRENT_FIFO_INL
#define IOX_HOOFS_CONCURRENT_FIFO_INL

#include "iceoryx_hoofs/internal/concurrent/fifo.hpp"
#ifndef IOX_HOOFS_CONCURRENT_BUFFER_SPSC_FIFO_INL
#define IOX_HOOFS_CONCURRENT_BUFFER_SPSC_FIFO_INL

#include "iox/detail/spsc_fifo.hpp"

namespace iox
{
namespace concurrent
{
template <class ValueType, uint64_t Capacity>
inline bool FiFo<ValueType, Capacity>::push(const ValueType& value) noexcept
inline bool SpscFifo<ValueType, Capacity>::push(const ValueType& value) noexcept
{
if (is_full())
{
Expand All @@ -42,31 +43,31 @@ inline bool FiFo<ValueType, Capacity>::push(const ValueType& value) noexcept
}

template <class ValueType, uint64_t Capacity>
inline bool FiFo<ValueType, Capacity>::is_full() const noexcept
inline bool SpscFifo<ValueType, Capacity>::is_full() const noexcept
{
return m_write_pos.load(std::memory_order_relaxed) == m_read_pos.load(std::memory_order_relaxed) + Capacity;
}

template <class ValueType, uint64_t Capacity>
inline uint64_t FiFo<ValueType, Capacity>::size() const noexcept
inline uint64_t SpscFifo<ValueType, Capacity>::size() const noexcept
{
return m_write_pos.load(std::memory_order_relaxed) - m_read_pos.load(std::memory_order_relaxed);
}

template <class ValueType, uint64_t Capacity>
inline constexpr uint64_t FiFo<ValueType, Capacity>::capacity() noexcept
inline constexpr uint64_t SpscFifo<ValueType, Capacity>::capacity() noexcept
{
return Capacity;
}

template <class ValueType, uint64_t Capacity>
inline bool FiFo<ValueType, Capacity>::empty() const noexcept
inline bool SpscFifo<ValueType, Capacity>::empty() const noexcept
{
return m_read_pos.load(std::memory_order_relaxed) == m_write_pos.load(std::memory_order_relaxed);
}

template <class ValueType, uint64_t Capacity>
inline optional<ValueType> FiFo<ValueType, Capacity>::pop() noexcept
inline optional<ValueType> SpscFifo<ValueType, Capacity>::pop() noexcept
{
auto currentReadPos = m_read_pos.load(std::memory_order_acquire);
bool isEmpty = (currentReadPos ==
Expand All @@ -88,4 +89,4 @@ inline optional<ValueType> FiFo<ValueType, Capacity>::pop() noexcept
} // namespace concurrent
} // namespace iox

#endif // IOX_HOOFS_CONCURRENT_FIFO_INL
#endif // IOX_HOOFS_CONCURRENT_BUFFER_SPSC_FIFO_INL
4 changes: 2 additions & 2 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/variant_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#define IOX_HOOFS_CXX_VARIANT_QUEUE_HPP

#include "iceoryx_hoofs/concurrent/resizeable_lockfree_queue.hpp"
#include "iceoryx_hoofs/internal/concurrent/fifo.hpp"
#include "iceoryx_hoofs/internal/concurrent/sofi.hpp"
#include "iox/detail/spsc_fifo.hpp"
#include "iox/optional.hpp"
#include "iox/variant.hpp"

Expand Down Expand Up @@ -69,7 +69,7 @@ template <typename ValueType, uint64_t Capacity>
class VariantQueue
{
public:
using fifo_t = variant<concurrent::FiFo<ValueType, Capacity>,
using fifo_t = variant<concurrent::SpscFifo<ValueType, Capacity>,
concurrent::SoFi<ValueType, Capacity>,
concurrent::ResizeableLockFreeQueue<ValueType, Capacity>,
concurrent::ResizeableLockFreeQueue<ValueType, Capacity>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ inline VariantQueue<ValueType, Capacity>::VariantQueue(const VariantQueueTypes t
{
case VariantQueueTypes::FiFo_SingleProducerSingleConsumer:
{
m_fifo.template emplace<concurrent::FiFo<ValueType, Capacity>>();
m_fifo.template emplace<concurrent::SpscFifo<ValueType, Capacity>>();
break;
}
case VariantQueueTypes::SoFi_SingleProducerSingleConsumer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/internal/concurrent/fifo.hpp"
#include "iox/detail/spsc_fifo.hpp"

#include <gmock/gmock.h>
#include <gtest/gtest.h>
Expand All @@ -29,7 +29,7 @@ using namespace iox::concurrent;

constexpr uint64_t FIFO_CAPACITY = 10;

class FiFo_Test : public Test
class SpscFifo_Test : public Test
{
public:
void SetUp() override
Expand All @@ -40,10 +40,10 @@ class FiFo_Test : public Test
{
}

FiFo<uint64_t, FIFO_CAPACITY> sut;
SpscFifo<uint64_t, FIFO_CAPACITY> sut;
};

TEST_F(FiFo_Test, SinglePopSinglePush)
TEST_F(SpscFifo_Test, SinglePopSinglePush)
{
::testing::Test::RecordProperty("TEST_ID", "57059a17-ec89-42e3-a07c-4a53d0cdcb1d");
EXPECT_THAT(sut.push(25), Eq(true));
Expand All @@ -52,14 +52,14 @@ TEST_F(FiFo_Test, SinglePopSinglePush)
EXPECT_THAT(result.value(), Eq(25U));
}

TEST_F(FiFo_Test, PopFailsWhenEmpty)
TEST_F(SpscFifo_Test, PopFailsWhenEmpty)
{
::testing::Test::RecordProperty("TEST_ID", "0063d54a-e3cb-43f8-ac32-fd0ad94ba7e1");
auto result = sut.pop();
EXPECT_THAT(result.has_value(), Eq(false));
}

TEST_F(FiFo_Test, PushFailsWhenFull)
TEST_F(SpscFifo_Test, PushFailsWhenFull)
{
::testing::Test::RecordProperty("TEST_ID", "8d492e83-c0c3-47bd-b745-9f56e20199e9");
for (uint64_t k = 0; k < FIFO_CAPACITY; ++k)
Expand All @@ -69,7 +69,7 @@ TEST_F(FiFo_Test, PushFailsWhenFull)
EXPECT_THAT(sut.push(123), Eq(false));
}

TEST_F(FiFo_Test, IsEmptyWhenPopReturnsNullopt)
TEST_F(SpscFifo_Test, IsEmptyWhenPopReturnsNullopt)
{
::testing::Test::RecordProperty("TEST_ID", "81a538c8-f366-4625-8aad-d83ab1d5ecf4");
for (uint64_t k = 0; k < FIFO_CAPACITY; ++k)
Expand All @@ -85,7 +85,7 @@ TEST_F(FiFo_Test, IsEmptyWhenPopReturnsNullopt)
EXPECT_THAT(sut.empty(), Eq(true));
}

TEST_F(FiFo_Test, OverflowTestWithPushPopAlternation)
TEST_F(SpscFifo_Test, OverflowTestWithPushPopAlternation)
{
::testing::Test::RecordProperty("TEST_ID", "6ea65156-ca3f-42fc-b199-1119696023c1");
for (uint64_t k = 0; k < 100 * FIFO_CAPACITY; ++k)
Expand All @@ -97,7 +97,7 @@ TEST_F(FiFo_Test, OverflowTestWithPushPopAlternation)
}
}

TEST_F(FiFo_Test, OverflowFromFullToEmptyRepetition)
TEST_F(SpscFifo_Test, OverflowFromFullToEmptyRepetition)
{
::testing::Test::RecordProperty("TEST_ID", "33a8c03f-5538-46b4-846e-9dec4badab0b");
uint64_t m = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#ifndef IOX_POSH_POPO_PORTS_INTERFACE_PORT_DATA_HPP
#define IOX_POSH_POPO_PORTS_INTERFACE_PORT_DATA_HPP

#include "iceoryx_hoofs/internal/concurrent/fifo.hpp"
#include "iceoryx_posh/capro/service_description.hpp"
#include "iceoryx_posh/iceoryx_posh_types.hpp"
#include "iceoryx_posh/internal/popo/ports/base_port_data.hpp"
#include "iox/detail/spsc_fifo.hpp"

namespace iox
{
Expand All @@ -31,7 +31,7 @@ struct InterfacePortData : public BasePortData
InterfacePortData() noexcept = default;
InterfacePortData(const RuntimeName_t& runtimeName, const capro::Interfaces interface) noexcept;

concurrent::FiFo<capro::CaproMessage, MAX_INTERFACE_CAPRO_FIFO_SIZE> m_caproMessageFiFo;
concurrent::SpscFifo<capro::CaproMessage, MAX_INTERFACE_CAPRO_FIFO_SIZE> m_caproMessageFiFo;
bool m_doInitialOfferForward{true};
};
} // namespace popo
Expand Down

0 comments on commit fd1f97b

Please sign in to comment.