From a6f2d8884aaa12133bcc7b8ec5ee6cc016585410 Mon Sep 17 00:00:00 2001 From: Graham Palmer Date: Fri, 27 Oct 2023 16:41:37 -0400 Subject: [PATCH] iox-#2067 Support move-only types in the LockFreeQueue Signed-off-by: Graham Palmer --- doc/website/release-notes/iceoryx-unreleased.md | 1 + .../concurrent/lockfree_queue/lockfree_queue.inl | 3 ++- .../lockfree_queue/resizeable_lockfree_queue.inl | 3 ++- .../test/moduletests/test_concurrent_lockfree_queue.cpp | 9 +++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index a4e00d7b82e..715137aeeae 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -54,6 +54,7 @@ **Bugfixes:** +- LockFreeQueue fails to support move-only types [\#2067](https://github.com/eclipse-iceoryx/iceoryx/issues/2067) - FreeBSD CI build is broken [\#1338](https://github.com/eclipse-iceoryx/iceoryx/issues/1338) - High CPU load in blocked publisher is reduced by introducing smart busy loop waiting (adaptive_wait) [\#1347](https://github.com/eclipse-iceoryx/iceoryx/issues/1347) - Compile Error : iceoryx_dds/Mempool.hpp: No such file or directory [\#1364](https://github.com/eclipse-iceoryx/iceoryx/issues/1364) diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/lockfree_queue/lockfree_queue.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/lockfree_queue/lockfree_queue.inl index 5efb54c5508..ecdb4a88afb 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/lockfree_queue/lockfree_queue.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/lockfree_queue/lockfree_queue.inl @@ -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. @@ -105,7 +106,7 @@ iox::optional LockFreeQueue::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(value)); m_usedIndices.push(index); diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/lockfree_queue/resizeable_lockfree_queue.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/lockfree_queue/resizeable_lockfree_queue.inl index 579ada89f73..89dc1ca94ee 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/lockfree_queue/resizeable_lockfree_queue.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/lockfree_queue/resizeable_lockfree_queue.inl @@ -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. @@ -213,7 +214,7 @@ iox::optional ResizeableLockFreeQueue::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(value)); Base::m_usedIndices.push(index); diff --git a/iceoryx_hoofs/test/moduletests/test_concurrent_lockfree_queue.cpp b/iceoryx_hoofs/test/moduletests/test_concurrent_lockfree_queue.cpp index b507ff0616c..389c25ee45e 100644 --- a/iceoryx_hoofs/test/moduletests/test_concurrent_lockfree_queue.cpp +++ b/iceoryx_hoofs/test/moduletests/test_concurrent_lockfree_queue.cpp @@ -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. @@ -39,6 +40,14 @@ struct Integer { } + // Delete copy constructor to ensure that the queue supports move-only types. + Integer(const Integer&) = delete; + Integer& operator=(const Integer&) = delete; + Integer(Integer&&) = default; + Integer& operator=(Integer&&) = default; + + ~Integer() = default; + int value{0}; // so that it behaves like an int for comparison purposes