Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SIMIX_io_finish becomes IoImp::finish
[simgrid.git] / src / simix / ActorImpl.cpp
index 67dbfcd..3b42e4c 100644 (file)
@@ -16,7 +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 +49,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 +64,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;
@@ -171,7 +169,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 +177,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)
@@ -399,7 +397,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 +427,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 +464,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 +497,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();
 }