Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simix::Comm: turn another function into a method
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 9 May 2016 18:32:16 +0000 (20:32 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 9 May 2016 18:32:16 +0000 (20:32 +0200)
src/simix/SynchroComm.cpp
src/simix/SynchroComm.hpp
src/simix/smx_network.cpp
src/simix/smx_network_private.h

index 74f8492..e066252 100644 (file)
@@ -20,7 +20,8 @@ simgrid::simix::Comm::Comm(e_smx_comm_type_t _type) {
 
   XBT_DEBUG("Create communicate synchro %p", this);
 }
-void simgrid::simix::Comm::suspend() {
+void simgrid::simix::Comm::suspend()
+{
   /* FIXME: shall we suspend also the timeout synchro? */
   if (surf_comm)
     surf_comm->suspend();
@@ -28,14 +29,16 @@ void simgrid::simix::Comm::suspend() {
 
 }
 
-void simgrid::simix::Comm::resume() {
+void simgrid::simix::Comm::resume()
+{
   /*FIXME: check what happen with the timeouts */
   if (surf_comm)
     surf_comm->resume();
   /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */
 }
 
-void simgrid::simix::Comm::cancel() {
+void simgrid::simix::Comm::cancel()
+{
   /* if the synchro is a waiting state means that it is still in a mbox */
   /* so remove from it and delete it */
   if (state == SIMIX_WAITING) {
@@ -51,7 +54,8 @@ void simgrid::simix::Comm::cancel() {
 }
 
 /**  @brief get the amount remaining from the communication */
-double simgrid::simix::Comm::remains() {
+double simgrid::simix::Comm::remains()
+{
   switch (state) {
 
   case SIMIX_RUNNING:
@@ -68,3 +72,22 @@ double simgrid::simix::Comm::remains() {
     break;
   }
 }
+
+/** @brief This is part of the cleanup process, probably an internal command */
+void simgrid::simix::Comm::cleanupSurf()
+{
+  if (surf_comm){
+    surf_comm->unref();
+    surf_comm = NULL;
+  }
+
+  if (src_timeout){
+    src_timeout->unref();
+    src_timeout = NULL;
+  }
+
+  if (dst_timeout){
+    dst_timeout->unref();
+    dst_timeout = NULL;
+  }
+}
index bdcc41e..70359b2 100644 (file)
@@ -26,6 +26,7 @@ namespace simix {
     void resume();
     void cancel();
     double remains();
+    void cleanupSurf(); // FIXME: make me protected
 
     e_smx_comm_type_t type;         /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
     smx_mailbox_t mbox = nullptr;   /* Rendez-vous where the comm is queued */
@@ -36,7 +37,7 @@ namespace simix {
                                        (used as garbage collector)) */
 #endif
     int refcount = 1;               /* Number of processes involved in the cond */
-    int detached = 0;               /* If detached or not */
+    bool detached = false;          /* If detached or not */
 
     void (*clean_fun)(void*);       /* Function to clean the detached src_buf if something goes wrong */
     int (*match_fun)(void*,void*,smx_synchro_t);  /* Filter function used by the other side. It is used when
@@ -58,7 +59,7 @@ namespace simix {
     void *dst_buff = nullptr;
     size_t src_buff_size;
     size_t *dst_buff_size;
-    unsigned copied = 0;          /* whether the data were already copied */
+    bool copied = false;          /* whether the data were already copied */
 
     void* src_data;                 /* User data associated to communication */
     void* dst_data;
index 7d0ffeb..6ba9c3b 100644 (file)
@@ -175,7 +175,7 @@ void SIMIX_comm_destroy(smx_synchro_t synchro)
       return;
   XBT_DEBUG("Really free communication %p; refcount is now %d", comm, comm->refcount);
 
-  SIMIX_comm_destroy_internal_actions(synchro);
+  comm->cleanupSurf();
 
   if (comm->detached && comm->state != SIMIX_DONE) {
     /* the communication has failed and was detached:
@@ -192,25 +192,6 @@ void SIMIX_comm_destroy(smx_synchro_t synchro)
   delete comm;
 }
 
-void SIMIX_comm_destroy_internal_actions(smx_synchro_t synchro)
-{
-  simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-  if (comm->surf_comm){
-    comm->surf_comm->unref();
-    comm->surf_comm = NULL;
-  }
-
-  if (comm->src_timeout){
-    comm->src_timeout->unref();
-    comm->src_timeout = NULL;
-  }
-
-  if (comm->dst_timeout){
-    comm->dst_timeout->unref();
-    comm->dst_timeout = NULL;
-  }
-}
-
 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,
@@ -442,9 +423,6 @@ smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int
 
 void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_synchro_t synchro, double timeout)
 {
-  /* the simcall may be a wait, a send or a recv */
-  surf_action_t sleep;
-
   /* Associate this simcall to the wait synchro */
   XBT_DEBUG("simcall_HANDLER_comm_wait, %p", synchro);
 
@@ -477,7 +455,7 @@ void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_synchro_t synchro, dou
   if (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING) {
     SIMIX_comm_finish(synchro);
   } else { /* if (timeout >= 0) { we need a surf sleep action even when there is no timeout, otherwise surf won't tell us when the host fails */
-    sleep = surf_host_sleep(simcall->issuer->host, timeout);
+    surf_action_t sleep = surf_host_sleep(simcall->issuer->host, timeout);
     sleep->setData(synchro);
 
     simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
@@ -606,7 +584,7 @@ static inline void SIMIX_comm_start(smx_synchro_t synchro)
       XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure",
                 sg_host_get_name(sender), sg_host_get_name(receiver));
       comm->state = SIMIX_LINK_FAILURE;
-      SIMIX_comm_destroy_internal_actions(synchro);
+      comm->cleanupSurf();
     }
 
     /* If any of the process is suspend, create the synchro but stop its execution,
@@ -789,7 +767,7 @@ void SIMIX_post_comm(smx_synchro_t synchro)
             comm, (int)comm->state, comm->src_proc, comm->dst_proc, comm->detached);
 
   /* destroy the surf actions associated with the Simix communication */
-  SIMIX_comm_destroy_internal_actions(comm);
+  comm->cleanupSurf();
 
   /* if there are simcalls associated with the synchro, then answer them */
   if (xbt_fifo_size(synchro->simcalls)) {
index 403e29a..5348478 100644 (file)
@@ -26,6 +26,7 @@ XBT_PRIVATE void SIMIX_mailbox_exit(void);
 XBT_PRIVATE smx_mailbox_t SIMIX_mbox_create(const char *name);
 XBT_PRIVATE smx_mailbox_t SIMIX_mbox_get_by_name(const char *name);
 XBT_PRIVATE void SIMIX_mbox_remove(smx_mailbox_t mbox, smx_synchro_t comm);
+
 XBT_PRIVATE void SIMIX_mbox_set_receiver(smx_mailbox_t mbox, smx_process_t proc);
 XBT_PRIVATE smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox,
                               void *dst_buff, size_t *dst_buff_size,
@@ -33,7 +34,6 @@ XBT_PRIVATE smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_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 void SIMIX_comm_destroy_internal_actions(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);