From 007b56d03513887636b84fc246e57d6c4f8b777e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 2 Feb 2021 18:09:51 +0000 Subject: [PATCH] Squashed commit of the following: commit 6107c4538be149137209d85e5f41031291bc7150 Author: John Wellbelove Date: Tue Feb 2 12:15:31 2021 +0000 Added move constructor and move assignment to etl::shared_message commit c9a5716012db9b614ea67660ebf64dcb790ce571 Author: John Wellbelove Date: Sun Jan 31 12:36:29 2021 +0000 Squashed commit of the following: commit e5f4eb6fb38c337c82fcc250f17a8f21eb788975 Author: John Wellbelove Date: Sun Jan 31 12:34:49 2021 +0000 Squashed commit of the following: commit 23c5f1d3f9b13ff9e46ce3de96aefeb655d5ed97 Author: John Wellbelove Date: Sun Jan 31 12:32:35 2021 +0000 Fixed rollover error for etl::queue_spsc_atomic Added 'required_alignment' parameter to 'allocate' for etl::imemeory_block_allocator. Updated QueuedMessageRouter example --- include/etl/shared_message.h | 37 +++++++++++++++++++++++++++++++++++- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++++ test/test_shared_message.cpp | 15 +++++++++++++++ 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/include/etl/shared_message.h b/include/etl/shared_message.h index 95d45cff..f5ea7e0e 100644 --- a/include/etl/shared_message.h +++ b/include/etl/shared_message.h @@ -85,6 +85,17 @@ namespace etl p_rcmessage->get_reference_counter().increment_reference_count(); } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Move constructor + //************************************************************************* + shared_message(etl::shared_message&& other) + : p_rcmessage(etl::move(other.p_rcmessage)) + { + other.p_rcmessage = ETL_NULLPTR; + } +#endif + //************************************************************************* /// Copy assignment operator //************************************************************************* @@ -106,13 +117,37 @@ namespace etl return *this; } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Move assignment operator + //************************************************************************* + shared_message& operator =(etl::shared_message&& other) + { + if (&other != this) + { + // Deal with the current message. + if (p_rcmessage->get_reference_counter().decrement_reference_count() == 0U) + { + p_rcmessage->release(); + } + + // Move over the new one. + p_rcmessage = etl::move(other.p_rcmessage); + other.p_rcmessage = ETL_NULLPTR; + } + + return *this; + } +#endif + //************************************************************************* /// Destructor /// Returns the message back to the pool it it is the last copy. //************************************************************************* ~shared_message() { - if (p_rcmessage->get_reference_counter().decrement_reference_count() == 0U) + if ((p_rcmessage != ETL_NULLPTR) && + (p_rcmessage->get_reference_counter().decrement_reference_count() == 0U)) { p_rcmessage->release(); } diff --git a/include/etl/version.h b/include/etl/version.h index f322966d..c3050e6d 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 19 #define ETL_VERSION_MINOR 5 -#define ETL_VERSION_PATCH 2 +#define ETL_VERSION_PATCH 3 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 4d2a3654..7220da59 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ETL Embedded Template Library", - "version": "19.5.2", + "version": "19.5.3", "author s": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index f45cfaeb..176e7491 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library ETL -version=19.5.2 +version=19.5.3 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 21d306e3..d744c11b 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +19.5.3 +Added move constructor and move assignment operator to etl::shared_message. + =============================================================================== 19.5.2 Fixed rollover error for etl::queue_spsc_atomic diff --git a/test/test_shared_message.cpp b/test/test_shared_message.cpp index fb7213c8..9fa320cb 100644 --- a/test/test_shared_message.cpp +++ b/test/test_shared_message.cpp @@ -179,6 +179,21 @@ namespace } }; + //************************************************************************* + TEST(test_move_constructor) + { + etl::shared_message sm1(std::move(etl::shared_message(message_pool, Message1(1)))); + CHECK_EQUAL(1, sm1.get_reference_count()); + } + + //************************************************************************* + TEST(test_move_assignemnt) + { + etl::shared_message sm2 = etl::shared_message(message_pool, Message1(2)); + sm2 = std::move(etl::shared_message(message_pool, Message1(3))); + CHECK_EQUAL(1, sm2.get_reference_count()); + } + //************************************************************************* TEST(test_send_to_routers) {