Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ptask_BMF: refactor code and loop scenarios
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index 6e206eb..49c758a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -141,12 +141,8 @@ void ActorImpl::cleanup_from_simix()
   engine->remove_actor(pid_);
   if (host_ && host_actor_list_hook.is_linked())
     host_->get_impl()->remove_actor(this);
-  if (not kernel_destroy_list_hook.is_linked()) {
-#if SIMGRID_HAVE_MC
-    engine->add_dead_actor_to_dynar(this);
-#endif
+  if (not kernel_destroy_list_hook.is_linked())
     engine->add_actor_to_destroy_list(*this);
-  }
 }
 
 void ActorImpl::cleanup()
@@ -173,6 +169,9 @@ void ActorImpl::cleanup()
     activity->cancel();
   activities_.clear();
 
+  while (not mailboxes.empty())
+    mailboxes.back()->set_receiver(nullptr);
+
   XBT_DEBUG("%s@%s(%ld) should not run anymore", get_cname(), get_host()->get_cname(), get_pid());
 
   if (EngineImpl::get_instance()->is_maestro(this)) /* Do not cleanup maestro */
@@ -193,7 +192,7 @@ void ActorImpl::cleanup()
   cleanup_from_simix();
 
   context_->set_wannadie(false); // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
-  actor::simcall([this] { s4u::Actor::on_termination(*get_ciface()); });
+  actor::simcall_answered([this] { s4u::Actor::on_termination(*get_ciface()); });
   context_->set_wannadie();
 }
 
@@ -204,28 +203,21 @@ void ActorImpl::exit()
   exception_          = nullptr;
 
   /* destroy the blocking synchro if any */
-  if (waiting_synchro_ != nullptr) {
-    waiting_synchro_->cancel();
-    waiting_synchro_->state_ = activity::State::FAILED;
-
-    activity::ExecImplPtr exec = boost::dynamic_pointer_cast<activity::ExecImpl>(waiting_synchro_);
-    activity::CommImplPtr comm = boost::dynamic_pointer_cast<activity::CommImpl>(waiting_synchro_);
-
-    if (exec != nullptr) {
-      exec->clean_action();
-    } else if (comm != nullptr) {
-      comm->unregister_simcall(&simcall_);
-    } else {
-      activity::ActivityImplPtr(waiting_synchro_)->finish();
-    }
-
+  if (auto activity = waiting_synchro_) {
     activities_.remove(waiting_synchro_);
     waiting_synchro_ = nullptr;
+
+    activity->cancel();
+    activity->set_state(activity::State::FAILED);
+    activity->post();
   }
   for (auto const& activity : activities_)
     activity->cancel();
   activities_.clear();
 
+  while (not mailboxes.empty())
+    mailboxes.back()->set_receiver(nullptr);
+
   // Forcefully kill the actor if its host is turned off. Not a HostFailureException because you should not survive that
   this->throw_exception(std::make_exception_ptr(ForcefulKillException(host_->is_on() ? "exited" : "host failed")));
 }
@@ -279,7 +271,6 @@ void ActorImpl::yield()
 
   /* Go into sleep and return control to maestro */
   context_->suspend();
-
   /* Ok, maestro returned control to us */
   XBT_DEBUG("Control returned to me: '%s'", get_cname());
 
@@ -305,7 +296,6 @@ void ActorImpl::yield()
       e.rethrow_nested(XBT_THROW_POINT, boost::core::demangle(typeid(e).name()) + " raised in kernel mode.");
     }
   }
-
 #if HAVE_SMPI
   if (not finished_)
     smpi_switch_data_segment(get_iface());
@@ -528,12 +518,6 @@ const char* SIMIX_process_self_get_name() // XBT_ATTRIB_DEPRECATED_v333
   return simgrid::s4u::Actor::is_maestro() ? "maestro" : simgrid::kernel::actor::ActorImpl::self()->get_cname();
 }
 
-/** @brief Returns the process from PID. */
-smx_actor_t SIMIX_process_from_PID(aid_t pid) // XBT_ATTRIB_DEPRECATED_v331
-{
-  return simgrid::kernel::actor::ActorImpl::by_pid(pid);
-}
-
 int SIMIX_is_maestro() // XBT_ATTRIB_DEPRECATED_v333
 {
   const auto* self = simgrid::kernel::actor::ActorImpl::self();