Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "Revert "actually fix the memleak around smpi's process_data" and "try to...
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 5 Feb 2018 15:15:21 +0000 (16:15 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 5 Feb 2018 15:15:21 +0000 (16:15 +0100)
This reverts commit c7c5def2870e604025be03b866967c0c5e293afe.

include/simgrid/s4u/Actor.hpp
src/s4u/s4u_actor.cpp
src/simix/ActorImpl.cpp
src/smpi/internals/smpi_global.cpp

index 670f502..147f538 100644 (file)
@@ -165,6 +165,8 @@ public:
 
   /** Signal to others that a new actor has been created **/
   static simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> onCreation;
 
   /** Signal to others that a new actor has been created **/
   static simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> onCreation;
+  /** Signal indicating that the given actor is about to disappear */
+  static simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> onDestruction;
 
   /** Create an actor using a function
    *
 
   /** Create an actor using a function
    *
index 5e07894..a81f54a 100644 (file)
@@ -22,6 +22,7 @@ namespace simgrid {
 namespace s4u {
 
 simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> s4u::Actor::onCreation;
 namespace s4u {
 
 simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> s4u::Actor::onCreation;
+simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> s4u::Actor::onDestruction;
 
 // ***** Actor creation *****
 ActorPtr Actor::self()
 
 // ***** Actor creation *****
 ActorPtr Actor::self()
index 935ca1b..a198260 100644 (file)
@@ -404,6 +404,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn
   simix_global->process_list[process->pid] = process;
   XBT_DEBUG("Inserting %s(%s) in the to_run list", process->getCname(), host->getCname());
   simix_global->process_to_run.push_back(process);
   simix_global->process_list[process->pid] = process;
   XBT_DEBUG("Inserting %s(%s) in the to_run list", process->getCname(), host->getCname());
   simix_global->process_to_run.push_back(process);
+  intrusive_ptr_add_ref(process);
 
   /* Tracing the process creation */
   TRACE_msg_process_create(process->getName(), process->pid, process->host);
 
   /* Tracing the process creation */
   TRACE_msg_process_create(process->getName(), process->pid, process->host);
@@ -425,7 +426,6 @@ void SIMIX_process_detach()
   auto process = context->process();
   simix_global->cleanup_process_function(process);
   context->attach_stop();
   auto process = context->process();
   simix_global->cleanup_process_function(process);
   context->attach_stop();
-  delete process;
 }
 
 /**
 }
 
 /**
@@ -783,6 +783,7 @@ smx_actor_t SIMIX_process_from_PID(aid_t PID)
 }
 
 void SIMIX_process_on_exit_runall(smx_actor_t process) {
 }
 
 void SIMIX_process_on_exit_runall(smx_actor_t process) {
+  simgrid::s4u::Actor::onDestruction(process->iface());
   smx_process_exit_status_t exit_status = (process->context->iwannadie) ? SMX_EXIT_FAILURE : SMX_EXIT_SUCCESS;
   while (not process->on_exit.empty()) {
     s_smx_process_exit_fun_t exit_fun = process->on_exit.back();
   smx_process_exit_status_t exit_status = (process->context->iwannadie) ? SMX_EXIT_FAILURE : SMX_EXIT_SUCCESS;
   while (not process->on_exit.empty()) {
     s_smx_process_exit_fun_t exit_fun = process->on_exit.back();
index 5b0bab3..091dcb2 100644 (file)
@@ -623,6 +623,13 @@ void SMPI_init(){
   simgrid::s4u::Actor::onCreation.connect([](simgrid::s4u::ActorPtr actor) {
     process_data.insert({actor, new simgrid::smpi::Process(actor, nullptr)});
   });
   simgrid::s4u::Actor::onCreation.connect([](simgrid::s4u::ActorPtr actor) {
     process_data.insert({actor, new simgrid::smpi::Process(actor, nullptr)});
   });
+  simgrid::s4u::Actor::onDestruction.connect([](simgrid::s4u::ActorPtr actor) {
+    if (process_data.find(actor) != process_data.end()) {
+      delete process_data.at(actor);
+      process_data.erase(actor);
+    }
+  });
+
   smpi_init_options();
   smpi_global_init();
   smpi_check_options();
   smpi_init_options();
   smpi_global_init();
   smpi_check_options();