Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use simgrid::xbt::intrusive_erase().
[simgrid.git] / src / simix / ActorImpl.cpp
index 40e0f17..2295dd3 100644 (file)
@@ -15,6 +15,7 @@
 #include "xbt/functional.hpp"
 #include "xbt/log.h"
 #include "xbt/sysdep.h"
+#include "xbt/utility.hpp"
 
 #include "simgrid/s4u/Host.hpp"
 
@@ -24,7 +25,7 @@
 #include "src/kernel/activity/SleepImpl.hpp"
 #include "src/kernel/activity/SynchroIo.hpp"
 #include "src/kernel/activity/SynchroRaw.hpp"
-#include "src/mc/mc_replay.h"
+#include "src/mc/mc_replay.hpp"
 #include "src/mc/remote/Client.hpp"
 #include "src/msg/msg_private.hpp"
 #include "src/surf/cpu_interface.hpp"
@@ -112,8 +113,8 @@ void SIMIX_process_cleanup(smx_actor_t process)
 
   XBT_DEBUG("%p should not be run anymore",process);
   simix_global->process_list.erase(process->pid);
-  if (process->host)
-    xbt_swag_remove(process, process->host->extension<simgrid::simix::Host>()->process_list);
+  if (process->host && process->host_process_list_hook.is_linked())
+    simgrid::xbt::intrusive_erase(process->host->extension<simgrid::simix::Host>()->process_list, *process);
   xbt_swag_insert(process, simix_global->process_to_destroy);
   process->context->iwannadie = 0;
 
@@ -340,7 +341,7 @@ smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, v
     host->extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
 
   /* Add the process to its host process list */
-  xbt_swag_insert(process, host->extension<simgrid::simix::Host>()->process_list);
+  host->extension<simgrid::simix::Host>()->process_list.push_back(*process);
 
   XBT_DEBUG("Start context '%s'", process->name.c_str());
 
@@ -351,7 +352,7 @@ smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, v
   intrusive_ptr_add_ref(process);
 
   /* Tracing the process creation */
-  TRACE_msg_process_create(process->getCname(), process->pid, process->host);
+  TRACE_msg_process_create(process->getName(), process->pid, process->host);
 
   return process;
 }
@@ -406,7 +407,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn
       process->setProperty(kv.first, kv.second);
 
   /* Add the process to it's host process list */
-  xbt_swag_insert(process, host->extension<simgrid::simix::Host>()->process_list);
+  host->extension<simgrid::simix::Host>()->process_list.push_back(*process);
 
   /* Now insert it in the global process list and in the process to run list */
   simix_global->process_list[process->pid] = process;
@@ -414,7 +415,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn
   simix_global->process_to_run.push_back(process);
 
   /* Tracing the process creation */
-  TRACE_msg_process_create(process->getCname(), process->pid, process->host);
+  TRACE_msg_process_create(process->getName(), process->pid, process->host);
 
   auto context = dynamic_cast<simgrid::kernel::context::AttachContext*>(process->context);
   if (not context)
@@ -464,6 +465,12 @@ void SIMIX_process_runall()
  */
 void SIMIX_process_kill(smx_actor_t process, smx_actor_t issuer) {
 
+  if (process->finished) {
+    XBT_DEBUG("Ignoring request to kill process %s@%s that is already dead", process->getCname(),
+              process->host->getCname());
+    return;
+  }
+
   XBT_DEBUG("Killing process %s@%s", process->getCname(), process->host->getCname());
 
   process->context->iwannadie = 1;
@@ -592,9 +599,9 @@ void SIMIX_process_killall(smx_actor_t issuer, int reset_pid)
 void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest)
 {
   xbt_assert((process != nullptr), "Invalid parameters");
-  xbt_swag_remove(process, process->host->extension<simgrid::simix::Host>()->process_list);
+  simgrid::xbt::intrusive_erase(process->host->extension<simgrid::simix::Host>()->process_list, *process);
   process->host = dest;
-  xbt_swag_insert(process, dest->extension<simgrid::simix::Host>()->process_list);
+  dest->extension<simgrid::simix::Host>()->process_list.push_back(*process);
 }
 
 void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t process)