Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Use simix simix::Mutex refcount support for s4u::Mutex
[simgrid.git] / src / simix / smx_process.cpp
index a5f5496..b47211a 100644 (file)
@@ -126,24 +126,24 @@ void SIMIX_process_empty_trash(void)
 
   while ((process = (smx_process_t) xbt_swag_extract(simix_global->process_to_destroy))) {
     XBT_DEBUG("Getting rid of %p",process);
-
-    delete process->context;
-
-    /* Free the exception allocated at creation time */
-    free(process->running_ctx);
-    xbt_dict_free(&process->properties);
-
-    xbt_fifo_free(process->comms);
-
-    xbt_dynar_free(&process->on_exit);
-
-    delete process;
+    intrusive_ptr_release(process);
   }
 }
 
 namespace simgrid {
 namespace simix {
 
+Process::~Process()
+{
+  delete this->context;
+  if (this->properties)
+    xbt_dict_free(&this->properties);
+  if (this->comms != nullptr)
+    xbt_fifo_free(this->comms);
+  if (this->on_exit)
+    xbt_dynar_free(&this->on_exit);
+}
+
 void create_maestro(std::function<void()> code)
 {
   smx_process_t maestro = nullptr;
@@ -153,8 +153,6 @@ void create_maestro(std::function<void()> code)
   maestro->ppid = -1;
   maestro->name = "";
   maestro->data = nullptr;
-  maestro->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
-  XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
 
   if (!code) {
     maestro->context = SIMIX_context_new(std::function<void()>(), nullptr, maestro);
@@ -273,13 +271,6 @@ smx_process_t SIMIX_process_create(
       std::move(code),
       simix_global->cleanup_process_function, process);
 
-    process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
-    XBT_RUNNING_CTX_INITIALIZE(process->running_ctx);
-
-    if(MC_is_active()){
-      MC_ignore_heap(process->running_ctx, sizeof(*process->running_ctx));
-    }
-
     /* Add properties */
     process->properties = properties;
 
@@ -363,13 +354,6 @@ smx_process_t SIMIX_process_attach(
   process->context = simix_global->context_factory->attach(
     simix_global->cleanup_process_function, process);
 
-  process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
-  XBT_RUNNING_CTX_INITIALIZE(process->running_ctx);
-
-  if(MC_is_active()){
-    MC_ignore_heap(process->running_ctx, sizeof(*process->running_ctx));
-  }
-
   /* Add properties */
   process->properties = properties;
 
@@ -450,7 +434,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) {
   process->context->iwannadie = 1;
   process->blocked = 0;
   process->suspended = 0;
-  process->doexception = 0;
+  process->exception = nullptr;
 
   /* destroy the blocking synchro if any */
   if (process->waiting_synchro) {
@@ -859,15 +843,16 @@ void SIMIX_process_yield(smx_process_t self)
 
   if (self->suspended) {
     XBT_DEBUG("Hey! I'm suspended.");
-    xbt_assert(!self->doexception, "Gasp! This exception may be lost by subsequent calls.");
+    xbt_assert(self->exception != nullptr, "Gasp! This exception may be lost by subsequent calls.");
     self->suspended = 0;
     SIMIX_process_suspend(self, self);
   }
 
-  if (self->doexception) {
+  if (self->exception != nullptr) {
     XBT_DEBUG("Wait, maestro left me an exception");
-    self->doexception = 0;
-    RETHROW;
+    std::exception_ptr exception = std::move(self->exception);
+    self->exception = nullptr;
+    std::rethrow_exception(std::move(exception));
   }
 
   if(SMPI_switch_data_segment && self->segment_index != -1){
@@ -875,16 +860,6 @@ void SIMIX_process_yield(smx_process_t self)
   }
 }
 
-/* callback: context fetching */
-xbt_running_ctx_t *SIMIX_process_get_running_context(void)
-{
-  smx_process_t process = SIMIX_process_self();
-  if (process)
-    return process->running_ctx;
-  else
-    return nullptr;
-}
-
 /* callback: termination */
 void SIMIX_process_exception_terminate(xbt_ex_t * e)
 {