Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SIMIX_comm_destroy() -> simix::Comm::unref()
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 9 May 2016 19:17:11 +0000 (21:17 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 9 May 2016 19:17:11 +0000 (21:17 +0200)
src/simix/SynchroComm.cpp
src/simix/SynchroComm.hpp
src/simix/smx_network.cpp
src/simix/smx_network_private.h
src/simix/smx_process.cpp

index e066252..5a5ccb5 100644 (file)
@@ -73,6 +73,34 @@ double simgrid::simix::Comm::remains()
   }
 }
 
   }
 }
 
+void simgrid::simix::Comm::unref()
+{
+  XBT_DEBUG("Destroy synchro %p (refcount: %d), state: %d", this, refcount, (int)state);
+
+  xbt_assert(refcount > 0,
+      "This comm has a negative refcount! You must not call test() or wait() more than once on a given communication.");
+
+  refcount--;
+  if (refcount > 0)
+      return;
+  XBT_DEBUG("Really free communication %p; refcount is now %d", this, refcount);
+
+  cleanupSurf();
+
+  if (detached && state != SIMIX_DONE) {
+    /* the communication has failed and was detached:
+     * we have to free the buffer */
+    if (clean_fun)
+      clean_fun(src_buff);
+    src_buff = NULL;
+  }
+
+  if(mbox)
+    SIMIX_mbox_remove(mbox, this);
+
+  delete this;
+}
+
 /** @brief This is part of the cleanup process, probably an internal command */
 void simgrid::simix::Comm::cleanupSurf()
 {
 /** @brief This is part of the cleanup process, probably an internal command */
 void simgrid::simix::Comm::cleanupSurf()
 {
index 70359b2..0f85b83 100644 (file)
@@ -26,6 +26,7 @@ namespace simix {
     void resume();
     void cancel();
     double remains();
     void resume();
     void cancel();
     double remains();
+    void unref();
     void cleanupSurf(); // FIXME: make me protected
 
     e_smx_comm_type_t type;         /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
     void cleanupSurf(); // FIXME: make me protected
 
     e_smx_comm_type_t type;         /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
index 60e7900..40144d4 100644 (file)
@@ -155,43 +155,6 @@ static smx_synchro_t _find_matching_comm(std::deque<smx_synchro_t> *deque, e_smx
 /******************************************************************************/
 /*                          Communication synchros                            */
 /******************************************************************************/
 /******************************************************************************/
 /*                          Communication synchros                            */
 /******************************************************************************/
-
-/**
- *  \brief Destroy a communicate synchro
- *  \param synchro The communicate synchro to be destroyed
- */
-void SIMIX_comm_destroy(smx_synchro_t synchro)
-{
-  simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
-  XBT_DEBUG("Destroy synchro %p (refcount: %d), state: %d", comm, comm->refcount, (int)comm->state);
-
-  if (comm->refcount <= 0) {
-    xbt_backtrace_display_current();
-    xbt_die("This comm has a negative refcount! You must not call test() or wait() more than once on a given communication.");
-  }
-  comm->refcount--;
-  if (comm->refcount > 0)
-      return;
-  XBT_DEBUG("Really free communication %p; refcount is now %d", comm, comm->refcount);
-
-  comm->cleanupSurf();
-
-  if (comm->detached && comm->state != SIMIX_DONE) {
-    /* the communication has failed and was detached:
-     * we have to free the buffer */
-    if (comm->clean_fun) {
-      comm->clean_fun(comm->src_buff);
-    }
-    comm->src_buff = NULL;
-  }
-
-  if(comm->mbox)
-    SIMIX_mbox_remove(comm->mbox, comm);
-
-  delete comm;
-}
-
 void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_process_t src, smx_mailbox_t mbox,
                                   double task_size, double rate,
                                   void *src_buff, size_t src_buff_size,
 void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_process_t src, smx_mailbox_t mbox,
                                   double task_size, double rate,
                                   void *src_buff, size_t src_buff_size,
@@ -215,7 +178,7 @@ smx_synchro_t simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_process_t sr
   XBT_DEBUG("send from %p", mbox);
 
   /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
   XBT_DEBUG("send from %p", mbox);
 
   /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
-  smx_synchro_t this_synchro = new simgrid::simix::Comm(SIMIX_COMM_SEND);
+  simgrid::simix::Comm* this_synchro = new simgrid::simix::Comm(SIMIX_COMM_SEND);
 
   /* Look for communication synchro matching our needs. We also provide a description of
    * ourself so that the other side also gets a chance of choosing if it wants to match with us.
 
   /* Look for communication synchro matching our needs. We also provide a description of
    * ourself so that the other side also gets a chance of choosing if it wants to match with us.
@@ -244,8 +207,7 @@ smx_synchro_t simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_process_t sr
     }
   } else {
     XBT_DEBUG("Receive already pushed");
     }
   } else {
     XBT_DEBUG("Receive already pushed");
-
-    SIMIX_comm_destroy(this_synchro);
+    this_synchro->unref();
 
     other_comm->state = SIMIX_READY;
     other_comm->type = SIMIX_COMM_READY;
 
     other_comm->state = SIMIX_READY;
     other_comm->type = SIMIX_COMM_READY;
@@ -310,7 +272,7 @@ smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox, void
     void *data, double rate)
 {
   XBT_DEBUG("recv from %p %p", mbox, mbox->comm_queue);
     void *data, double rate)
 {
   XBT_DEBUG("recv from %p %p", mbox, mbox->comm_queue);
-  smx_synchro_t this_synchro = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
+  simgrid::simix::Comm* this_synchro = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
 
   smx_synchro_t other_synchro;
   //communication already done, get it inside the fifo of completed comms
 
   smx_synchro_t other_synchro;
   //communication already done, get it inside the fifo of completed comms
@@ -334,7 +296,7 @@ smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox, void
         other_comm->mbox = NULL;
       }
       other_comm->refcount--;
         other_comm->mbox = NULL;
       }
       other_comm->refcount--;
-      SIMIX_comm_destroy(this_synchro);
+      static_cast<simgrid::simix::Comm*>(this_synchro)->unref();
     }
   } else {
     /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
     }
   } else {
     /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
@@ -350,7 +312,7 @@ smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox, void
       other_synchro = this_synchro;
       SIMIX_mbox_push(mbox, this_synchro);
     } else {
       other_synchro = this_synchro;
       SIMIX_mbox_push(mbox, this_synchro);
     } else {
-      SIMIX_comm_destroy(this_synchro);
+      this_synchro->unref();
       simgrid::simix::Comm *other_comm = static_cast<simgrid::simix::Comm*>(other_synchro);
 
       other_comm->state = SIMIX_READY;
       simgrid::simix::Comm *other_comm = static_cast<simgrid::simix::Comm*>(other_synchro);
 
       other_comm->state = SIMIX_READY;
@@ -392,24 +354,24 @@ smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int
                               int tag, int (*match_fun)(void *, void *, smx_synchro_t), void *data)
 {
   XBT_DEBUG("iprobe from %p %p", mbox, mbox->comm_queue);
                               int tag, int (*match_fun)(void *, void *, smx_synchro_t), void *data)
 {
   XBT_DEBUG("iprobe from %p %p", mbox, mbox->comm_queue);
-  smx_synchro_t this_synchro;
+  simgrid::simix::Comm* this_comm;
   int smx_type;
   if(type == 1){
   int smx_type;
   if(type == 1){
-    this_synchro = new simgrid::simix::Comm(SIMIX_COMM_SEND);
+    this_comm = new simgrid::simix::Comm(SIMIX_COMM_SEND);
     smx_type = SIMIX_COMM_RECEIVE;
   } else{
     smx_type = SIMIX_COMM_RECEIVE;
   } else{
-    this_synchro = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
+    this_comm = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
     smx_type = SIMIX_COMM_SEND;
   } 
   smx_synchro_t other_synchro=NULL;
   if(mbox->permanent_receiver && ! mbox->done_comm_queue->empty()){
     XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something");
     other_synchro =
     smx_type = SIMIX_COMM_SEND;
   } 
   smx_synchro_t other_synchro=NULL;
   if(mbox->permanent_receiver && ! mbox->done_comm_queue->empty()){
     XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something");
     other_synchro =
-        _find_matching_comm(mbox->done_comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_synchro,/*remove_matching*/false);
+        _find_matching_comm(mbox->done_comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false);
   }
   if (!other_synchro){
     XBT_DEBUG("check if we have more luck in the normal mailbox");
   }
   if (!other_synchro){
     XBT_DEBUG("check if we have more luck in the normal mailbox");
-    other_synchro = _find_matching_comm(mbox->comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_synchro,/*remove_matching*/false);
+    other_synchro = _find_matching_comm(mbox->comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false);
   }
 
   if(other_synchro) {
   }
 
   if(other_synchro) {
@@ -417,7 +379,7 @@ smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int
     other_comm->refcount--;
   }
 
     other_comm->refcount--;
   }
 
-  SIMIX_comm_destroy(this_synchro);
+  this_comm->unref();
   return other_synchro;
 }
 
   return other_synchro;
 }
 
@@ -733,7 +695,7 @@ void SIMIX_comm_finish(smx_synchro_t synchro)
   }
 
   while (destroy_count-- > 0)
   }
 
   while (destroy_count-- > 0)
-    SIMIX_comm_destroy(synchro);
+    static_cast<simgrid::simix::Comm*>(synchro)->unref();
 }
 
 /**
 }
 
 /**
index 8a60c4c..1451a8e 100644 (file)
@@ -33,7 +33,6 @@ XBT_PRIVATE smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t
                               int (*)(void *, void *, smx_synchro_t),
                               void (*copy_data_fun)(smx_synchro_t, void*, size_t),
                               void *data, double rate);
                               int (*)(void *, void *, smx_synchro_t),
                               void (*copy_data_fun)(smx_synchro_t, void*, size_t),
                               void *data, double rate);
-XBT_PRIVATE void SIMIX_comm_destroy(smx_synchro_t synchro);
 XBT_PRIVATE smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int type, int src,
                               int tag, int (*match_fun)(void *, void *, smx_synchro_t), void *data);
 XBT_PRIVATE void SIMIX_post_comm(smx_synchro_t synchro);
 XBT_PRIVATE smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int type, int src,
                               int tag, int (*match_fun)(void *, void *, smx_synchro_t), void *data);
 XBT_PRIVATE void SIMIX_post_comm(smx_synchro_t synchro);
index 1bd0a3b..95e411c 100644 (file)
@@ -83,7 +83,7 @@ void SIMIX_process_cleanup(smx_process_t process)
       if (comm->detached)
         XBT_DEBUG("Don't destroy it since it's a detached comm and I'm the sender");
       else
       if (comm->detached)
         XBT_DEBUG("Don't destroy it since it's a detached comm and I'm the sender");
       else
-        SIMIX_comm_destroy(comm);
+        comm->unref();
 
     }
     else if (comm->dst_proc == process){
 
     }
     else if (comm->dst_proc == process){
@@ -95,7 +95,7 @@ void SIMIX_process_cleanup(smx_process_t process)
         /* the comm will be freed right now, remove it from the sender */
         xbt_fifo_remove(comm->src_proc->comms, comm);
       }
         /* the comm will be freed right now, remove it from the sender */
         xbt_fifo_remove(comm->src_proc->comms, comm);
       }
-      SIMIX_comm_destroy(comm);
+      comm->unref();
     } else {
       xbt_die("Communication synchro %p is in my list but I'm not the sender nor the receiver", synchro);
     }
     } else {
       xbt_die("Communication synchro %p is in my list but I'm not the sender nor the receiver", synchro);
     }
@@ -508,7 +508,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) {
       xbt_fifo_remove(process->comms, process->waiting_synchro);
       comm->cancel();
       xbt_fifo_remove(process->waiting_synchro->simcalls, &process->simcall);
       xbt_fifo_remove(process->comms, process->waiting_synchro);
       comm->cancel();
       xbt_fifo_remove(process->waiting_synchro->simcalls, &process->simcall);
-      SIMIX_comm_destroy(process->waiting_synchro);
+      comm->unref();
 
     } else if (sleep != nullptr) {
       SIMIX_process_sleep_destroy(process->waiting_synchro);
 
     } else if (sleep != nullptr) {
       SIMIX_process_sleep_destroy(process->waiting_synchro);