Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factor un-registration of simcall.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 20 Mar 2021 17:45:38 +0000 (18:45 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 22 Mar 2021 10:48:32 +0000 (11:48 +0100)
src/kernel/activity/ActivityImpl.cpp
src/kernel/activity/ActivityImpl.hpp
src/kernel/activity/CommImpl.cpp
src/kernel/activity/ExecImpl.cpp
src/kernel/actor/ActorImpl.cpp

index 026c416..b8b2eae 100644 (file)
@@ -7,6 +7,7 @@
 #include "simgrid/modelchecker.h"
 #include "src/mc/mc_replay.hpp"
 #include "src/simix/smx_private.hpp"
+#include <boost/range/algorithm.hpp>
 #include <cmath> // isfinite()
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
@@ -27,6 +28,14 @@ void ActivityImpl::register_simcall(smx_simcall_t simcall)
   simcall->issuer_->waiting_synchro_ = this;
 }
 
+void ActivityImpl::unregister_simcall(smx_simcall_t simcall)
+{
+  // Remove the first occurrence of simcall:
+  auto j = boost::range::find(simcalls_, simcall);
+  if (j != simcalls_.end())
+    simcalls_.erase(j);
+}
+
 void ActivityImpl::clean_action()
 {
   if (surf_action_) {
index 4ba5273..cc34a08 100644 (file)
@@ -60,6 +60,7 @@ public:
                              // the model or because it terminated without waiting for the model
 
   virtual void register_simcall(smx_simcall_t simcall);
+  void unregister_simcall(smx_simcall_t simcall);
   void clean_action();
   virtual double get_remaining() const;
   const char* get_state_str() const;
index e26fecf..d512914 100644 (file)
@@ -16,7 +16,6 @@
 #include "src/surf/network_interface.hpp"
 #include "src/surf/surf_interface.hpp"
 
-#include <boost/range/algorithm.hpp>
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related synchronization");
 
 XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t src, smx_mailbox_t mbox, double task_size,
@@ -284,13 +283,8 @@ static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall)
   simgrid::kernel::activity::CommImpl** comms = simcall_comm_waitany__get__comms(simcall);
   size_t count                                = simcall_comm_waitany__get__count(simcall);
 
-  for (size_t i = 0; i < count; i++) {
-    // Remove the first occurrence of simcall:
-    auto* comm = comms[i];
-    auto j     = boost::range::find(comm->simcalls_, simcall);
-    if (j != comm->simcalls_.end())
-      comm->simcalls_.erase(j);
-  }
+  for (size_t i = 0; i < count; i++)
+    comms[i]->unregister_simcall(simcall);
 }
 void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comms[], size_t count,
                                   double timeout)
index 214676d..2b7a046 100644 (file)
@@ -16,8 +16,6 @@
 
 #include "simgrid/s4u/Host.hpp"
 
-#include <boost/range/algorithm.hpp>
-
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
 
 namespace simgrid {
@@ -171,10 +169,7 @@ void ExecImpl::finish()
       const auto* execs = observer->get_execs();
 
       for (auto* exec : *execs) {
-        // Remove the first occurrence of simcall:
-        auto j = boost::range::find(exec->simcalls_, simcall);
-        if (j != exec->simcalls_.end())
-          exec->simcalls_.erase(j);
+        exec->unregister_simcall(simcall);
 
         if (simcall->timeout_cb_) {
           simcall->timeout_cb_->remove();
@@ -254,12 +249,8 @@ void ExecImpl::wait_any_for(actor::ActorImpl* issuer, const std::vector<ExecImpl
   } else {
     issuer->simcall_.timeout_cb_ = simgrid::simix::Timer::set(SIMIX_get_clock() + timeout, [issuer, execs]() {
       issuer->simcall_.timeout_cb_ = nullptr;
-      for (auto* exec : *execs) {
-        // Remove the first occurrence of simcall:
-        auto j = boost::range::find(exec->simcalls_, &issuer->simcall_);
-        if (j != exec->simcalls_.end())
-          exec->simcalls_.erase(j);
-      }
+      for (auto* exec : *execs)
+        exec->unregister_simcall(&issuer->simcall_);
       simix::marshal<int>(issuer->simcall_.result_, -1);
       issuer->simcall_answer();
     });
index 1d6cb85..0db05cc 100644 (file)
@@ -19,7 +19,6 @@
 #include "src/surf/cpu_interface.hpp"
 
 #include <boost/core/demangle.hpp>
-#include <boost/range/algorithm.hpp>
 #include <utility>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX (process)");
@@ -227,10 +226,7 @@ void ActorImpl::exit()
     if (exec != nullptr) {
       exec->clean_action();
     } else if (comm != nullptr) {
-      // Remove first occurrence of &actor->simcall:
-      auto i = boost::range::find(waiting_synchro_->simcalls_, &simcall_);
-      if (i != waiting_synchro_->simcalls_.end())
-        waiting_synchro_->simcalls_.remove(&simcall_);
+      comm->unregister_simcall(&simcall_);
     } else {
       activity::ActivityImplPtr(waiting_synchro_)->finish();
     }