Skip to content

Commit

Permalink
Merge pull request #2068 from gpalmer-latai/iox-2067-support-move-in-…
Browse files Browse the repository at this point in the history
…lockfreequeue

iox-#2067 Support move-only types in the LockFreeQueue
  • Loading branch information
elBoberido authored Oct 31, 2023
2 parents 775c7ac + 7e053fa commit 8bc6075
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
- MacOS tests that use `EXPECT_DEATH` stuck [#898](https://github.com/eclipse-iceoryx/iceoryx/issues/898)
- Remove `EXPECT_DEATH` [#1613](https://github.com/eclipse-iceoryx/iceoryx/issues/1613)
- ServiceDiscovery uses instrospection MemPools [#1359](https://github.com/eclipse-iceoryx/iceoryx/issues/1359)
- LockFreeQueue fails to support move-only types [\#2067](https://github.com/eclipse-iceoryx/iceoryx/issues/2067)

**Refactoring:**

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2023 by Latitude AI. 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.
Expand Down Expand Up @@ -105,7 +106,7 @@ iox::optional<ElementType> LockFreeQueue<ElementType, Capacity>::pushImpl(T&& va

// if we removed from a full queue via popIfFull it might not be full anymore when a concurrent pop occurs

writeBufferAt(index, value); //&& version is called due to explicit conversion via std::move
writeBufferAt(index, std::forward<T>(value));

m_usedIndices.push(index);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2023 by Latitude AI. 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.
Expand Down Expand Up @@ -213,7 +214,7 @@ iox::optional<ElementType> ResizeableLockFreeQueue<ElementType, MaxCapacity>::pu

// if we removed from a full queue via popIfFull it might not be full anymore when a concurrent pop occurs

Base::writeBufferAt(index, value);
Base::writeBufferAt(index, std::forward<T>(value));

Base::m_usedIndices.push(index);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2023 by Latitude AI. 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.
Expand Down Expand Up @@ -49,6 +50,23 @@ struct Integer
}
};

// non-POD type used to ensure that the queue supports move-only types.
struct MoveOnlyInteger : public Integer
{
// NOLINTNEXTLINE(hicpp-explicit-conversions) required for typed tests
MoveOnlyInteger(int value = 0)
: Integer(value)
{
}

MoveOnlyInteger(const MoveOnlyInteger&) = delete;
MoveOnlyInteger& operator=(const MoveOnlyInteger&) = delete;
MoveOnlyInteger(MoveOnlyInteger&&) = default;
MoveOnlyInteger& operator=(MoveOnlyInteger&&) = default;

~MoveOnlyInteger() = default;
};

template <typename Config>
class LockFreeQueueTest : public ::testing::Test
{
Expand Down Expand Up @@ -130,33 +148,43 @@ using AlmostEmpty = Config<QueueType, ElementType, Capacity, 1>;
using LFFull1 = Full<LFQueue, int, 1>;
using LFFull2 = Full<LFQueue, int, 1000>;
using LFFull3 = Full<LFQueue, Integer, 100>;
using LFFull4 = Full<LFQueue, MoveOnlyInteger, 10>;

// configs of the resizeable lockfree queue
using Full1 = Full<RLFQueue, Integer, 1>;
using Full2 = Full<RLFQueue, Integer, 10>;
using Full3 = Full<RLFQueue, int, 1000>;
using Full4 = Full<RLFQueue, MoveOnlyInteger, 100>;

using AlmostFull1 = AlmostFull<RLFQueue, Integer, 10>;
using AlmostFull2 = AlmostFull<RLFQueue, int, 1000>;
using AlmostFull3 = AlmostFull<RLFQueue, MoveOnlyInteger, 100>;

using HalfFull1 = HalfFull<RLFQueue, Integer, 10>;
using HalfFull2 = HalfFull<RLFQueue, int, 1000>;
using HalfFull3 = HalfFull<RLFQueue, MoveOnlyInteger, 100>;

using AlmostEmpty1 = AlmostEmpty<RLFQueue, Integer, 10>;
using AlmostEmpty2 = AlmostEmpty<RLFQueue, int, 1000>;
using AlmostEmpty3 = AlmostEmpty<RLFQueue, MoveOnlyInteger, 100>;

typedef ::testing::Types<LFFull1,
LFFull2,
LFFull3,
LFFull4,
Full1,
Full2,
Full3,
Full4,
AlmostFull1,
AlmostFull2,
AlmostFull3,
HalfFull1,
HalfFull2,
HalfFull3,
AlmostEmpty1,
AlmostEmpty2>
AlmostEmpty2,
AlmostEmpty3>
TestConfigs;

TYPED_TEST_SUITE(LockFreeQueueTest, TestConfigs, );
Expand Down

0 comments on commit 8bc6075

Please sign in to comment.