Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add SIMIX_rdv_{set,get}_data; tiny fixups
[simgrid.git] / src / simix / smx_network.c
index f57266e..9c421ab 100644 (file)
@@ -82,6 +82,7 @@ smx_comm_t SIMIX_rdv_get_request(smx_rdv_t rdv, smx_comm_type_t type)
     DEBUG0("Communication request found!");
     xbt_fifo_shift(rdv->comm_fifo);
     SIMIX_communication_use(comm);
+    comm->rdv = NULL;    
     return comm;
   }
 
@@ -122,6 +123,14 @@ smx_comm_t SIMIX_rdv_get_head(smx_rdv_t rdv)
   return (smx_comm_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(rdv->comm_fifo));
 }
 
+/** @brief adds some API-related data to the rendez-vous point */
+void SIMIX_rdv_set_data(smx_rdv_t rdv,void *data) {
+  rdv->data=data;
+}
+/** @brief gets API-related data from the rendez-vous point */
+void *SIMIX_rdv_get_data(smx_rdv_t rdv) {
+  return rdv->data;
+}
 
 /******************************************************************************/
 /*                           Communication Requests                           */
@@ -150,13 +159,20 @@ smx_comm_t SIMIX_communication_new(smx_comm_type_t type)
 void SIMIX_communication_destroy(smx_comm_t comm)
 {
   comm->refcount--;
-  if(comm->refcount == 0){
-    if(comm->act != NULL)
-      SIMIX_action_destroy(comm->act);
+  if(comm->refcount > 0)
+    return;
 
-    xbt_free(comm->cond);
-    xbt_free(comm);
+  if(comm->cond){
+    SIMIX_cond_destroy(comm->cond);
+    comm->cond = NULL;
   }
+  
+  if(comm->act){
+    SIMIX_action_destroy(comm->act);
+    comm->act = NULL;
+  }
+  
+  xbt_free(comm);
 }
 
 /**
@@ -174,7 +190,7 @@ static inline void SIMIX_communication_use(smx_comm_t comm)
 
 /**
  *  \brief Start the simulation of a communication request
- *  \param comm The communication request
+ *  \param comm The   comm->rdv = NULL;communication request
  */
 static inline void SIMIX_communication_start(smx_comm_t comm)
 {
@@ -229,7 +245,7 @@ static inline void SIMIX_communication_wait_for_completion(smx_comm_t comm, doub
           SIMIX_communication_cancel(comm);
         else
           SIMIX_rdv_remove(comm->rdv, comm);
-          
+
         SIMIX_cond_signal(comm->cond);
         SIMIX_communication_destroy(comm);
       }
@@ -243,14 +259,14 @@ static inline void SIMIX_communication_wait_for_completion(smx_comm_t comm, doub
   
   /* Check for errors other than timeouts (they are catched above) */
   if(!SIMIX_host_get_state(SIMIX_host_self())){
+    if(comm->rdv)
+      SIMIX_rdv_remove(comm->rdv, comm);
     SIMIX_communication_destroy(comm);
     THROW0(host_error, 0, "Host failed");
   } else if (SIMIX_action_get_state(comm->act) == SURF_ACTION_FAILED){
     SIMIX_communication_destroy(comm);
     THROW0(network_error, 0, "Link failure");
   }
-
-  SIMIX_unregister_action_to_condition(comm->act, comm->cond);
 }
 
 /**
@@ -288,7 +304,8 @@ void SIMIX_network_copy_data(smx_comm_t comm)
   dst_buff_size = MIN(dst_buff_size, src_buff_size);
   
   /* Update the receiver's buffer size to the copied amount */
-  *comm->dst_buff_size = dst_buff_size;
+  if (comm->dst_buff_size)
+    *comm->dst_buff_size = dst_buff_size;
 
   if(dst_buff_size == 0)
     return;
@@ -410,16 +427,16 @@ void SIMIX_network_recv(smx_rdv_t rdv, double timeout, void *dst_buff,
 /*                        Asynchronous Communication                          */
 /******************************************************************************/
 
-/*
+
 void SIMIX_network_wait(smx_action_t comm, double timeout)
 {
-  TO BE IMPLEMENTED
+  THROW_UNIMPLEMENTED;
 }
 
 XBT_PUBLIC(int) SIMIX_network_test(smx_action_t comm)
 {
-  TO BE IMPLEMENTED
-}*/
+  THROW_UNIMPLEMENTED;
+}