Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplify SIMIX_host_add_auto_restart_process
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 1 Jul 2018 17:15:57 +0000 (19:15 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 1 Jul 2018 17:15:57 +0000 (19:15 +0200)
src/simix/ActorImpl.cpp
src/simix/ActorImpl.hpp
src/simix/smx_host.cpp
src/simix/smx_host_private.hpp

index 55cd833..38b423d 100644 (file)
@@ -709,9 +709,7 @@ void SIMIX_process_yield(smx_actor_t self)
     SIMIX_process_on_exit_runall(self);
     /* Add the process to the list of process to restart, only if the host is down */
     if (self->auto_restart_ && self->host_->is_off()) {
     SIMIX_process_on_exit_runall(self);
     /* Add the process to the list of process to restart, only if the host is down */
     if (self->auto_restart_ && self->host_->is_off()) {
-      SIMIX_host_add_auto_restart_process(self->host_, self->get_cname(), self->code, self->get_user_data(),
-                                          SIMIX_timer_get_date(self->kill_timer), self->get_properties(),
-                                          self->auto_restart_);
+      SIMIX_host_add_auto_restart_process(self->host_, self);
     }
     XBT_DEBUG("Process %s@%s is dead", self->get_cname(), self->host_->get_cname());
     self->context_->stop();
     }
     XBT_DEBUG("Process %s@%s is dead", self->get_cname(), self->host_->get_cname());
     self->context_->stop();
index 5d610f7..1a3c47b 100644 (file)
@@ -23,29 +23,6 @@ namespace simgrid {
 namespace kernel {
 namespace actor {
 
 namespace kernel {
 namespace actor {
 
-class ProcessArg {
-public:
-  std::string name;
-  std::function<void()> code;
-  void* data            = nullptr;
-  s4u::Host* host       = nullptr;
-  double kill_time      = 0.0;
-  std::shared_ptr<std::unordered_map<std::string, std::string>> properties;
-  bool auto_restart     = false;
-  ProcessArg()          = default;
-  explicit ProcessArg(std::string name, std::function<void()> code, void* data, s4u::Host* host, double kill_time,
-                      std::shared_ptr<std::unordered_map<std::string, std::string>> properties, bool auto_restart)
-      : name(name)
-      , code(std::move(code))
-      , data(data)
-      , host(host)
-      , kill_time(kill_time)
-      , properties(properties)
-      , auto_restart(auto_restart)
-  {
-  }
-};
-
 class ActorImpl : public simgrid::surf::PropertyHolder {
 public:
   ActorImpl() : piface_(this) {}
 class ActorImpl : public simgrid::surf::PropertyHolder {
 public:
   ActorImpl() : piface_(this) {}
@@ -126,6 +103,41 @@ public:
   void* get_user_data() { return userdata_; }
 };
 
   void* get_user_data() { return userdata_; }
 };
 
+class ProcessArg {
+public:
+  std::string name;
+  std::function<void()> code;
+  void* data                                                               = nullptr;
+  s4u::Host* host                                                          = nullptr;
+  double kill_time                                                         = 0.0;
+  std::shared_ptr<std::unordered_map<std::string, std::string>> properties = nullptr;
+  bool auto_restart                                                        = false;
+  ProcessArg()                                                             = default;
+
+  explicit ProcessArg(std::string name, std::function<void()> code, void* data, s4u::Host* host, double kill_time,
+                      std::shared_ptr<std::unordered_map<std::string, std::string>> properties, bool auto_restart)
+      : name(name)
+      , code(std::move(code))
+      , data(data)
+      , host(host)
+      , kill_time(kill_time)
+      , properties(properties)
+      , auto_restart(auto_restart)
+  {
+  }
+
+  explicit ProcessArg(s4u::Host* host, ActorImpl* actor)
+      : name(actor->get_name())
+      , code(std::move(actor->code))
+      , data(actor->get_user_data())
+      , host(host)
+      , kill_time(SIMIX_timer_get_date(actor->kill_timer))
+      , auto_restart(actor->auto_restart_)
+  {
+    properties.reset(actor->get_properties(), [](decltype(actor->get_properties())) {});
+  }
+};
+
 /* Used to keep the list of actors blocked on a synchro  */
 typedef boost::intrusive::list<ActorImpl, boost::intrusive::member_hook<ActorImpl, boost::intrusive::list_member_hook<>,
                                                                         &ActorImpl::smx_synchro_hook>>
 /* Used to keep the list of actors blocked on a synchro  */
 typedef boost::intrusive::list<ActorImpl, boost::intrusive::member_hook<ActorImpl, boost::intrusive::list_member_hook<>,
                                                                         &ActorImpl::smx_synchro_hook>>
index afd0d0c..3e565cb 100644 (file)
@@ -78,13 +78,9 @@ const char* sg_host_self_get_name()
  * The processes will only be restarted once, meaning that you will have to register the process
  * again to restart the process again.
  */
  * The processes will only be restarted once, meaning that you will have to register the process
  * again to restart the process again.
  */
-void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, simgrid::simix::ActorCode code, void* data,
-                                         double kill_time, std::unordered_map<std::string, std::string>* properties,
-                                         int auto_restart)
+void SIMIX_host_add_auto_restart_process(sg_host_t host, simgrid::kernel::actor::ActorImpl* actor)
 {
 {
-  simgrid::kernel::actor::ProcessArg* arg =
-      new simgrid::kernel::actor::ProcessArg(name, code, data, host, kill_time, nullptr, auto_restart);
-  arg->properties.reset(properties, [](decltype(properties)) {});
+  simgrid::kernel::actor::ProcessArg* arg = new simgrid::kernel::actor::ProcessArg(host, actor);
 
   if (host->is_off() && watched_hosts.find(host->get_cname()) == watched_hosts.end()) {
     watched_hosts.insert(host->get_cname());
 
   if (host->is_off() && watched_hosts.find(host->get_cname()) == watched_hosts.end()) {
     watched_hosts.insert(host->get_cname());
index 1fd1796..87d081a 100644 (file)
@@ -38,11 +38,7 @@ public:
 }
 }
 
 }
 }
 
-XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, std::function<void()> code,
-                                                     void* data, double kill_time,
-                                                     std::unordered_map<std::string, std::string>* properties,
-                                                     int auto_restart);
-
+XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, simgrid::kernel::actor::ActorImpl* actor);
 XBT_PRIVATE void SIMIX_host_autorestart(sg_host_t host);
 
 XBT_PRIVATE void SIMIX_execution_finish(smx_activity_t synchro);
 XBT_PRIVATE void SIMIX_host_autorestart(sg_host_t host);
 
 XBT_PRIVATE void SIMIX_execution_finish(smx_activity_t synchro);