From 9f3191b6aff8255bea1eb76ba31cbe22edcd17c3 Mon Sep 17 00:00:00 2001 From: jparisu Date: Thu, 11 Aug 2022 13:59:09 +0200 Subject: [PATCH 1/4] Create a new Sugar class Signed-off-by: jparisu --- .../ddsrouter_utils/atomic/Atomicable.hpp | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 ddsrouter_utils/include/ddsrouter_utils/atomic/Atomicable.hpp diff --git a/ddsrouter_utils/include/ddsrouter_utils/atomic/Atomicable.hpp b/ddsrouter_utils/include/ddsrouter_utils/atomic/Atomicable.hpp new file mode 100644 index 000000000..19a20a1be --- /dev/null +++ b/ddsrouter_utils/include/ddsrouter_utils/atomic/Atomicable.hpp @@ -0,0 +1,65 @@ +// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/** + * @file OwnerPtr.hpp + * + * This file contains class OwnerPtr definition. + */ + +#ifndef _DDSROUTERUTILS_ATOMIC_ATOMICABLE_HPP_ +#define _DDSROUTERUTILS_ATOMIC_ATOMICABLE_HPP_ + +#include +#include + +namespace eprosima { +namespace ddsrouter { +namespace utils { + +/** + * @brief Sugar class to join any type value and a mutex together for commodity and readability. + * + * @tparam Type actual type of the object. + * @tparam Mutex class of the mutex. Default std::mutex but could be recursive, shared, etc. + * + * @note as primitive types are not classes, are not allowed in this class. + * + * EXAMPLE OF USE + * Atomic f; + * std::unique_lock lock(f); + * f.foo(); + */ +template +class Atomicable : public Type , public Mutex +{ + // Nothing to add +}; + +/** + * Alias to use a Atomicable object with a shared time mutex. + * + * EXAMPLE OF USE + * Atomic f; + * std::shared_lock lock(f); + * f.foo(); + */ +template +using SharedAtomicable = Atomicable; + +} /* namespace utils */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + +#endif /* _DDSROUTERUTILS_ATOMIC_ATOMICABLE_HPP_ */ From 9caf210c11e46e2ba912d8f0ae10a681b1e1a3fa Mon Sep 17 00:00:00 2001 From: jparisu Date: Mon, 5 Sep 2022 14:08:36 +0200 Subject: [PATCH 2/4] Move Atomicable to types Signed-off-by: jparisu --- .../{atomic => types}/Atomicable.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) rename ddsrouter_utils/include/ddsrouter_utils/{atomic => types}/Atomicable.hpp (81%) diff --git a/ddsrouter_utils/include/ddsrouter_utils/atomic/Atomicable.hpp b/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp similarity index 81% rename from ddsrouter_utils/include/ddsrouter_utils/atomic/Atomicable.hpp rename to ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp index 19a20a1be..f98f6a92a 100644 --- a/ddsrouter_utils/include/ddsrouter_utils/atomic/Atomicable.hpp +++ b/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp @@ -13,13 +13,13 @@ // limitations under the License. /** - * @file OwnerPtr.hpp + * @file Atomicable.hpp * - * This file contains class OwnerPtr definition. + * This file contains class Atomicable definition. */ -#ifndef _DDSROUTERUTILS_ATOMIC_ATOMICABLE_HPP_ -#define _DDSROUTERUTILS_ATOMIC_ATOMICABLE_HPP_ +#ifndef _DDSROUTERUTILS_TYPES_ATOMICABLE_HPP_ +#define _DDSROUTERUTILS_TYPES_ATOMICABLE_HPP_ #include #include @@ -29,15 +29,15 @@ namespace ddsrouter { namespace utils { /** - * @brief Sugar class to join any type value and a mutex together for commodity and readability. + * @brief Utils class to join any type value and a mutex together for commodity and readability. * * @tparam Type actual type of the object. * @tparam Mutex class of the mutex. Default std::mutex but could be recursive, shared, etc. * - * @note as primitive types are not classes, are not allowed in this class. + * @note as primitive types are not classes, are not allowed in this class. Use std::atomic instead. * * EXAMPLE OF USE - * Atomic f; + * Atomicable f; * std::unique_lock lock(f); * f.foo(); */ @@ -62,4 +62,4 @@ using SharedAtomicable = Atomicable; } /* namespace ddsrouter */ } /* namespace eprosima */ -#endif /* _DDSROUTERUTILS_ATOMIC_ATOMICABLE_HPP_ */ +#endif /* _DDSROUTERUTILS_TYPES_ATOMICABLE_HPP_ */ From b2c420f6b186cbdf31a7fdc6ceade7b8691910dc Mon Sep 17 00:00:00 2001 From: jparisu Date: Mon, 5 Sep 2022 14:12:52 +0200 Subject: [PATCH 3/4] uncrustify Signed-off-by: jparisu --- ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp b/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp index f98f6a92a..324d96ec4 100644 --- a/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp +++ b/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp @@ -42,7 +42,7 @@ namespace utils { * f.foo(); */ template -class Atomicable : public Type , public Mutex +class Atomicable : public Type, public Mutex { // Nothing to add }; From 144ed7a28e63b34563740043e4271f858ee091e2 Mon Sep 17 00:00:00 2001 From: jparisu Date: Mon, 5 Sep 2022 15:26:21 +0200 Subject: [PATCH 4/4] apply suggestions Signed-off-by: jparisu --- ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp b/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp index 324d96ec4..4ae011e4d 100644 --- a/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp +++ b/ddsrouter_utils/include/ddsrouter_utils/types/Atomicable.hpp @@ -51,7 +51,7 @@ class Atomicable : public Type, public Mutex * Alias to use a Atomicable object with a shared time mutex. * * EXAMPLE OF USE - * Atomic f; + * SharedAtomicable f; * std::shared_lock lock(f); * f.foo(); */