Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move maxmin solver from system
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index 47b901ce5ef7164d20aa1a4a456d5d8c85e8bada..ef37508256cc9e9cd4844003a2894a1313a2995a 100644 (file)
@@ -29,7 +29,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_actor, kernel, "Logging specific to Actor's
  *
  * @return The SIMIX process
  */
-smx_actor_t SIMIX_process_self() // XBT_ATTRIB_DEPRECATED_v333
+simgrid::kernel::actor::ActorImpl* SIMIX_process_self() // XBT_ATTRIB_DEPRECATED_v333
 {
   return simgrid::kernel::actor::ActorImpl::self();
 }
@@ -48,7 +48,7 @@ unsigned long* get_maxpid_addr()
 {
   return &maxpid;
 }
-ActorIDTrait::ActorIDTrait(std::string name, aid_t ppid) : name_(std::move(name)), pid_(maxpid++), ppid_(ppid) {}
+ActorIDTrait::ActorIDTrait(const std::string& name, aid_t ppid) : name_(name), pid_(maxpid++), ppid_(ppid) {}
 
 ActorImpl* ActorImpl::self()
 {
@@ -137,10 +137,12 @@ bool ActorImpl::is_maestro() const
 
 void ActorImpl::cleanup_from_kernel()
 {
-  xbt_assert(s4u::Actor::is_maestro(), "Cleanup_from_kernel called from '%s' on '%s'", ActorImpl::self()->get_cname(),
-             get_cname());
+  xbt_assert(s4u::Actor::is_maestro(), "Cleanup_from_kernel must be called in maestro context");
 
   auto* engine = EngineImpl::get_instance();
+  if (engine->get_actor_by_pid(get_pid()) == nullptr)
+    return; // Already cleaned
+
   engine->remove_actor(get_pid());
   if (host_ && host_actor_list_hook.is_linked())
     host_->get_impl()->remove_actor(this);
@@ -154,6 +156,7 @@ void ActorImpl::cleanup_from_kernel()
   }
 
   undaemonize();
+  s4u::Actor::on_termination(*get_ciface());
 
   while (not mailboxes_.empty())
     mailboxes_.back()->set_receiver(nullptr);
@@ -191,8 +194,9 @@ void ActorImpl::cleanup_from_self()
     simcall_.timeout_cb_ = nullptr;
   }
 
-  set_wannadie(false); // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
-  actor::simcall_answered([this] { s4u::Actor::on_termination(*get_ciface()); });
+  /* maybe the actor was killed during a simcall, reset its observer */
+  simcall_.observer_ = nullptr;
+
   set_wannadie();
 }