Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix 'on_exit' preservation which failed when auto_restart was set first (FG#11).
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index 9a646da..86b8b59 100644 (file)
@@ -93,8 +93,7 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h
 
   /* Add properties */
   if (properties != nullptr)
-    for (auto const& kv : *properties)
-      actor->set_property(kv.first, kv.second);
+    actor->set_properties(*properties);
 
   /* Add the process to it's host process list */
   host->pimpl_->process_list_.push_back(*actor);
@@ -142,11 +141,8 @@ void ActorImpl::cleanup()
 
   // Execute the termination callbacks
   bool failed = context_->iwannadie;
-  while (not on_exit.empty()) {
-    auto exit_fun = on_exit.back();
-    on_exit.pop_back();
-    exit_fun(failed);
-  }
+  for (auto exit_fun = on_exit->crbegin(); exit_fun != on_exit->crend(); ++exit_fun)
+    (*exit_fun)(failed);
 
   /* cancel non-blocking activities */
   for (auto activity : comms)
@@ -334,6 +330,7 @@ s4u::Actor* ActorImpl::restart()
   // start the new actor
   ActorImplPtr actor =
       ActorImpl::create(arg.name, std::move(arg.code), arg.data, arg.host, arg.properties.get(), nullptr);
+  *actor->on_exit = std::move(*arg.on_exit);
   actor->set_kill_time(arg.kill_time);
   actor->set_auto_restart(arg.auto_restart);
 
@@ -487,8 +484,7 @@ ActorImplPtr ActorImpl::create(const std::string& name, const simix::ActorCode&
 
   /* Add properties */
   if (properties != nullptr)
-    for (auto const& kv : *properties)
-      actor->set_property(kv.first, kv.second);
+    actor->set_properties(*properties);
 
   actor->start(code);
 
@@ -652,7 +648,7 @@ void SIMIX_process_on_exit(smx_actor_t actor, const std::function<void(int, void
 void SIMIX_process_on_exit(smx_actor_t actor, const std::function<void(bool /*failed*/)>& fun)
 {
   xbt_assert(actor, "current process not found: are you in maestro context ?");
-  actor->on_exit.emplace_back(fun);
+  actor->on_exit->emplace_back(fun);
 }
 
 /** @brief Restart a process, starting it again from the beginning. */