Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Misc. Sonar smells.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 27 Jun 2023 11:46:43 +0000 (13:46 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 27 Jun 2023 15:01:01 +0000 (17:01 +0200)
examples/cpp/task-switch-host/s4u-task-switch-host.cpp
src/mc/api/strategy/Strategy.hpp
src/mc/api/strategy/UniformStrategy.hpp
src/s4u/s4u_Task.cpp

index 7023f68..eee90e6 100644 (file)
@@ -53,7 +53,7 @@ int main(int argc, char* argv[])
   // Add a function to be called before each firing of comm0
   // This function modifies the graph of tasks by adding or removing
   // successors to comm0
-  comm0->on_this_start_cb([comm0, exec1, exec2, jupiter, fafard](sg4::Task*) {
+  comm0->on_this_start_cb([comm0, exec1, exec2, jupiter, fafard](const sg4::Task*) {
     static int count = 0;
     if (count % 2 == 0) {
       comm0->set_destination(jupiter);
index 96eb753..5e7b492 100644 (file)
@@ -35,7 +35,7 @@ public:
   virtual std::pair<aid_t, int> best_transition(bool must_be_todo) const = 0;
 
   /** Returns the best transition among those that should be interleaved. */
-  std::pair<aid_t, int> next_transition() { return best_transition(true); }
+  std::pair<aid_t, int> next_transition() const { return best_transition(true); }
 
   /** Allows for the strategy to update its fields knowing that the actor aid will
    *  be executed and a children strategy will then be created. */  
index cc5bd85..2a90f7b 100644 (file)
@@ -9,12 +9,12 @@
 #include "src/mc/transition/Transition.hpp"
 #include "xbt/random.hpp"
 
-#define MAX_RAND 100000
-
 namespace simgrid::mc {
 
 /** Guiding strategy that valuate states randomly */
 class UniformStrategy : public Strategy {
+  static constexpr int MAX_RAND = 100000;
+
   std::map<aid_t, int> valuation;
 
 public:
@@ -25,7 +25,7 @@ public:
   }
   void copy_from(const Strategy* strategy) override
   {
-    for (auto& [aid, _] : actors_to_run_)
+    for (auto const& [aid, _] : actors_to_run_)
       valuation[aid] = xbt::random::uniform_int(0, MAX_RAND);
   }
 
index bda7ec1..9419363 100644 (file)
@@ -45,9 +45,10 @@ bool Task::ready_to_run() const
 void Task::receive(Task* source)
 {
   XBT_DEBUG("Task %s received a token from %s", name_.c_str(), source->name_.c_str());
-  auto source_count = predecessors_[source]++;
+  auto source_count = predecessors_[source];
+  predecessors_[source]++;
   if (tokens_received_.size() <= queued_firings_ + source_count)
-    tokens_received_.push_back({});
+    tokens_received_.emplace_back();
   tokens_received_[queued_firings_ + source_count][source] = source->token_;
   bool enough_tokens = true;
   for (auto const& [key, val] : predecessors_)
@@ -130,7 +131,7 @@ void Task::fire() {
   on_start(this);
   working_ = true;
   queued_firings_ = std::max(queued_firings_ - 1, 0);
-  if (tokens_received_.size() > 0)
+  if (not tokens_received_.empty())
     tokens_received_.pop_front();
 }