Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference parameters in src/kernel/.
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index 1e5e15e..fdf73a3 100644 (file)
@@ -82,10 +82,10 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h
 {
   // This is mostly a copy/paste from create(), it'd be nice to share some code between those two functions.
 
-  XBT_DEBUG("Attach process %s on host '%s'", name.c_str(), host->get_cname());
+  XBT_DEBUG("Attach actor %s on host '%s'", name.c_str(), host->get_cname());
 
   if (not host->is_on()) {
-    XBT_WARN("Cannot launch process '%s' on failed host '%s'", name.c_str(), host->get_cname());
+    XBT_WARN("Cannot attach actor '%s' on failed host '%s'", name.c_str(), host->get_cname());
     throw HostFailureException(XBT_THROW_POINT, "Cannot attach actor on failed host.");
   }
 
@@ -102,10 +102,10 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h
   if (properties != nullptr)
     actor->set_properties(*properties);
 
-  /* Add the process to it's host process list */
+  /* Add the actor to it's host actor list */
   host->pimpl_->add_actor(actor);
 
-  /* Now insert it in the global process list and in the process to run list */
+  /* Now insert it in the global actor list and in the actors to run list */
   simix_global->process_list[actor->get_pid()] = actor;
   XBT_DEBUG("Inserting [%p] %s(%s) in the to_run list", actor, actor->get_cname(), host->get_cname());
   simix_global->actors_to_run.push_back(actor);
@@ -136,6 +136,20 @@ void ActorImpl::detach()
   context->attach_stop();
 }
 
+void ActorImpl::cleanup_from_simix()
+{
+  const std::lock_guard<std::mutex> lock(simix_global->mutex);
+  simix_global->process_list.erase(pid_);
+  if (host_ && host_actor_list_hook.is_linked())
+    host_->pimpl_->remove_actor(this);
+  if (not smx_destroy_list_hook.is_linked()) {
+#if SIMGRID_HAVE_MC
+    xbt_dynar_push_as(simix_global->dead_actors_vector, ActorImpl*, this);
+#endif
+    simix_global->actors_to_destroy.push_back(*this);
+  }
+}
+
 void ActorImpl::cleanup()
 {
   finished_ = true;
@@ -172,20 +186,7 @@ void ActorImpl::cleanup()
     kill_timer->remove();
     kill_timer = nullptr;
   }
-
-  simix_global->mutex.lock();
-
-  simix_global->process_list.erase(pid_);
-  if (host_ && host_actor_list_hook.is_linked())
-    host_->pimpl_->remove_actor(this);
-  if (not smx_destroy_list_hook.is_linked()) {
-#if SIMGRID_HAVE_MC
-    xbt_dynar_push_as(simix_global->dead_actors_vector, ActorImpl*, this);
-#endif
-    simix_global->actors_to_destroy.push_back(*this);
-  }
-
-  simix_global->mutex.unlock();
+  cleanup_from_simix();
 
   context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
   actor::simcall([this] { s4u::Actor::on_termination(*ciface()); });
@@ -391,7 +392,7 @@ void ActorImpl::resume()
   XBT_OUT();
 }
 
-activity::ActivityImplPtr ActorImpl::join(ActorImpl* actor, double timeout)
+activity::ActivityImplPtr ActorImpl::join(const ActorImpl* actor, double timeout)
 {
   activity::ActivityImplPtr sleep = this->sleep(timeout);
   actor->on_exit->emplace_back([sleep](bool) {