From 47d0461ca727ac3e9790279e37f392cd039f040a Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 24 May 2023 14:28:22 +0200 Subject: [PATCH] Fix some sonar issues in includes, after upgrade to c++17. --- include/simgrid/kernel/resource/Action.hpp | 3 ++- include/simgrid/plugins/ProducerConsumer.hpp | 4 ++-- include/simgrid/s4u/Activity.hpp | 20 +++++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/simgrid/kernel/resource/Action.hpp b/include/simgrid/kernel/resource/Action.hpp index 9524e89e0a..b75750e30b 100644 --- a/include/simgrid/kernel/resource/Action.hpp +++ b/include/simgrid/kernel/resource/Action.hpp @@ -13,6 +13,7 @@ #include #include #include +#include static constexpr double NO_MAX_DURATION = -1.0; @@ -225,7 +226,7 @@ public: /** @brief Get the tracing category associated to the current action */ const std::string& get_category() const { return category_; } /** @brief Set the tracing category of the current Action */ - void set_category(const std::string& category) { category_ = category; } + void set_category(std::string_view category) { category_ = category; } /** @brief Get the sharing_penalty (RTT or 1/thread_count) of the current Action */ double get_sharing_penalty() const { return sharing_penalty_; }; diff --git a/include/simgrid/plugins/ProducerConsumer.hpp b/include/simgrid/plugins/ProducerConsumer.hpp index 87d4cfa9a1..d4438e4ad7 100644 --- a/include/simgrid/plugins/ProducerConsumer.hpp +++ b/include/simgrid/plugins/ProducerConsumer.hpp @@ -140,7 +140,7 @@ public: */ s4u::CommPtr put_async(T* data, size_t simulated_size_in_bytes) { - std::unique_lock lock(*mutex_); + std::unique_lock lock(*mutex_); s4u::CommPtr comm = nullptr; XBT_CVERB(producer_consumer, (size() < max_queue_size_) ? "can put" : "must wait"); @@ -177,7 +177,7 @@ public: */ s4u::CommPtr get_async(T** data) { - std::unique_lock lock(*mutex_); + std::unique_lock lock(*mutex_); s4u::CommPtr comm = nullptr; XBT_CVERB(producer_consumer, empty() ? "must wait" : "can get"); while (empty()) diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index 0dade947b8..fb157dd8b6 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -74,8 +75,8 @@ protected: { if(this == a) throw std::invalid_argument("Cannot be its own successor"); - auto p = std::find_if(successors_.begin(), successors_.end(), [a](ActivityPtr const& i){ return i.get() == a.get(); }); - if (p != successors_.end()) + + if (std::any_of(begin(successors_), end(successors_), [a](ActivityPtr const& i) { return i.get() == a.get(); })) throw std::invalid_argument("Dependency already exists"); successors_.push_back(a); @@ -87,12 +88,13 @@ protected: if(this == a) throw std::invalid_argument("Cannot ask to remove itself from successors list"); - auto p = std::find_if(successors_.begin(), successors_.end(), [a](ActivityPtr const& i){ return i.get() == a.get(); }); - if (p != successors_.end()){ - successors_.erase(p); - a->dependencies_.erase({this}); - } else + auto p = + std::find_if(successors_.begin(), successors_.end(), [a](ActivityPtr const& i) { return i.get() == a.get(); }); + if (p == successors_.end()) throw std::invalid_argument("Dependency does not exist. Can not be removed."); + + successors_.erase(p); + a->dependencies_.erase({this}); } static std::set* vetoed_activities_; @@ -262,7 +264,7 @@ public: Activity::remove_successor(a); return static_cast(this); } - AnyActivity* set_name(const std::string& name) + AnyActivity* set_name(std::string_view name) { name_ = name; return static_cast(this); @@ -270,7 +272,7 @@ public: const std::string& get_name() const override { return name_; } const char* get_cname() const override { return name_.c_str(); } - AnyActivity* set_tracing_category(const std::string& category) + AnyActivity* set_tracing_category(std::string_view category) { xbt_assert(get_state() == State::INITED || get_state() == State::STARTING, "Cannot change the tracing category of an activity after its start"); -- 2.20.1