Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
prevent segfault when DEBUG is activated
[simgrid.git] / src / simix / ActorImpl.cpp
index 67dbfcd..e31c9c5 100644 (file)
@@ -16,8 +16,6 @@
 #include "src/mc/mc_replay.hpp"
 #include "src/mc/remote/Client.hpp"
 #include "src/simix/smx_host_private.hpp"
-#include "src/simix/smx_io_private.hpp"
-#include "src/simix/smx_synchro_private.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 
@@ -50,30 +48,6 @@ int SIMIX_process_has_pending_comms(smx_actor_t process) {
   return process->comms.size() > 0;
 }
 
-/**
- * @brief Moves a process to the list of processes to destroy.
- */
-void SIMIX_process_cleanup(smx_actor_t process)
-{
-  XBT_DEBUG("Cleanup process %s (%p), waiting synchro %p", process->get_cname(), process,
-            process->waiting_synchro.get());
-
-  simix_global->mutex.lock();
-
-  simix_global->process_list.erase(process->get_pid());
-  if (process->get_host() && process->host_process_list_hook.is_linked())
-    simgrid::xbt::intrusive_erase(process->get_host()->pimpl_->process_list_, *process);
-  if (not process->smx_destroy_list_hook.is_linked()) {
-#if SIMGRID_HAVE_MC
-    xbt_dynar_push_as(simix_global->dead_actors_vector, smx_actor_t, process);
-#endif
-    simix_global->actors_to_destroy.push_back(*process);
-  }
-  process->context_->iwannadie = false;
-
-  simix_global->mutex.unlock();
-}
-
 namespace simgrid {
 namespace kernel {
 namespace actor {
@@ -89,6 +63,29 @@ ActorImpl::~ActorImpl()
   delete this->context_;
 }
 
+void ActorImpl::cleanup()
+{
+  if (this == simix_global->maestro_process) /* Do not cleanup maestro */
+    return;
+
+  XBT_DEBUG("Cleanup actor %s (%p), waiting synchro %p", get_cname(), this, waiting_synchro.get());
+
+  simix_global->mutex.lock();
+
+  simix_global->process_list.erase(pid_);
+  if (host_ && host_process_list_hook.is_linked())
+    simgrid::xbt::intrusive_erase(host_->pimpl_->process_list_, *this);
+  if (not smx_destroy_list_hook.is_linked()) {
+#if SIMGRID_HAVE_MC
+    xbt_dynar_push_as(simix_global->dead_actors_vector, smx_actor_t, this);
+#endif
+    simix_global->actors_to_destroy.push_back(*this);
+  }
+  context_->iwannadie = false;
+
+  simix_global->mutex.unlock();
+}
+
 void ActorImpl::exit()
 {
   context_->iwannadie = true;
@@ -125,7 +122,7 @@ void ActorImpl::exit()
         sleep->surf_action_->cancel();
       sleep->post();
     } else if (raw != nullptr) {
-      SIMIX_synchro_stop_waiting(this, &simcall);
+      raw->finish();
     } else if (io != nullptr) {
       io->cancel();
     } else {
@@ -146,8 +143,8 @@ void ActorImpl::kill(ActorImpl* actor)
     return;
   }
 
-  XBT_DEBUG("Actor '%s'@%s is killing actor '%s'@%s", get_cname(), host_->get_cname(), actor->get_cname(),
-            actor->host_->get_cname());
+  XBT_DEBUG("Actor '%s'@%s is killing actor '%s'@%s", get_cname(), host_ ? host_->get_cname() : "", actor->get_cname(),
+            actor->host_ ? actor->host_->get_cname() : "");
 
   actor->exit();
 
@@ -171,7 +168,7 @@ void ActorImpl::set_kill_time(double kill_time)
   if (kill_time <= SIMIX_get_clock())
     return;
   XBT_DEBUG("Set kill time %f for actor %s@%s", kill_time, get_cname(), host_->get_cname());
-  kill_timer = SIMIX_timer_set(kill_time, [this] {
+  kill_timer = simix::Timer::set(kill_time, [this] {
     this->exit();
     kill_timer = nullptr;
   });
@@ -179,7 +176,7 @@ void ActorImpl::set_kill_time(double kill_time)
 
 double ActorImpl::get_kill_time()
 {
-  return SIMIX_timer_get_date(kill_timer);
+  return kill_timer ? kill_timer->get_date() : 0;
 }
 
 static void dying_daemon(int /*exit_status*/, void* data)
@@ -359,7 +356,7 @@ void ActorImpl::throw_exception(std::exception_ptr e)
 
     activity::RawImplPtr raw = boost::dynamic_pointer_cast<activity::RawImpl>(waiting_synchro);
     if (raw != nullptr) {
-      SIMIX_synchro_stop_waiting(this, &simcall);
+      raw->finish();
     }
 
     activity::IoImplPtr io = boost::dynamic_pointer_cast<activity::IoImpl>(waiting_synchro);
@@ -399,7 +396,7 @@ ActorImplPtr ActorImpl::create(std::string name, simix::ActorCode code, void* da
     actor->set_ppid(parent_actor->get_pid());
 
   XBT_VERB("Create context %s", actor->get_cname());
-  actor->context_ = SIMIX_context_new(std::move(code), &SIMIX_process_cleanup, actor);
+  actor->context_ = simix_global->context_factory->create_context(std::move(code), actor);
 
   /* Add properties */
   if (properties != nullptr)
@@ -429,7 +426,7 @@ void create_maestro(simix::ActorCode code)
   ActorImpl* maestro = new ActorImpl(xbt::string(""), /*host*/ nullptr);
 
   if (not code) {
-    maestro->context_ = SIMIX_context_new(simix::ActorCode(), nullptr, maestro);
+    maestro->context_ = simix_global->context_factory->create_context(simix::ActorCode(), maestro);
   } else {
     maestro->context_ = simix_global->context_factory->create_maestro(code, maestro);
   }
@@ -466,7 +463,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn
 
   XBT_VERB("Create context %s", actor->get_cname());
   xbt_assert(simix_global != nullptr, "simix is not initialized, please call MSG_init first");
-  actor->context_ = simix_global->context_factory->attach(&SIMIX_process_cleanup, actor);
+  actor->context_ = simix_global->context_factory->attach(actor);
 
   /* Add properties */
   if (properties != nullptr)
@@ -499,7 +496,7 @@ void SIMIX_process_detach()
   if (context == nullptr)
     xbt_die("Not a suitable context");
 
-  SIMIX_process_cleanup(context->get_actor());
+  context->get_actor()->cleanup();
   context->attach_stop();
 }
 
@@ -543,7 +540,7 @@ void SIMIX_process_throw(smx_actor_t actor, xbt_errcat_t cat, int value, const c
     simgrid::kernel::activity::RawImplPtr raw =
         boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(actor->waiting_synchro);
     if (raw != nullptr) {
-      SIMIX_synchro_stop_waiting(actor, &actor->simcall);
+      raw->finish();
     }
 
     simgrid::kernel::activity::IoImplPtr io =