+void SIMIX_comm_destroy(smx_action_t action)
+{
+ DEBUG2("Destroy action %p (refcount:%d)", action, action->comm.refcount);
+
+ if (action->comm.refcount <= 0)
+ xbt_die(bprintf("the refcount of comm %p is already 0 before decreasing it. That's a bug!",action));
+
+ action->comm.refcount--;
+ if (action->comm.refcount > 0)
+ return;
+ DEBUG2("Really free communication %p; refcount is now %d", action,
+ action->comm.refcount);
+
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+ action->latency_limited = SIMIX_comm_is_latency_bounded( action ) ;
+#endif
+
+#ifdef HAVE_TRACING
+ TRACE_smx_action_destroy(action);
+#endif
+
+ if (action->name)
+ xbt_free(action->name);
+
+ xbt_fifo_free(action->request_list);
+
+ SIMIX_comm_destroy_internal_actions(action);
+
+ if (action->comm.detached && action->state != SIMIX_DONE) {
+ /* the communication has failed and was detached:
+ * we have to free the buffer */
+ ((void_f_pvoid_t) action->comm.src_data)(action->comm.src_buff);
+ }
+
+ xbt_free(action);
+}
+
+void SIMIX_comm_destroy_internal_actions(smx_action_t action)
+{
+ if (action->comm.surf_comm){
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+ action->latency_limited = SIMIX_comm_is_latency_bounded(action);
+#endif
+ action->comm.surf_comm->model_type->action_unref(action->comm.surf_comm);
+ action->comm.surf_comm = NULL;
+ }
+
+ if (action->comm.src_timeout){
+ action->comm.src_timeout->model_type->action_unref(action->comm.src_timeout);
+ action->comm.src_timeout = NULL;
+ }
+
+ if (action->comm.dst_timeout){
+ action->comm.dst_timeout->model_type->action_unref(action->comm.dst_timeout);
+ action->comm.dst_timeout = NULL;
+ }
+}
+
+smx_action_t SIMIX_comm_isend(smx_process_t src_proc, smx_rdv_t rdv,
+ double task_size, double rate,
+ void *src_buff, size_t src_buff_size,
+ int (*match_fun)(void *, void *), void *data,
+ int detached)
+{
+ smx_action_t action;
+
+ /* Look for communication request matching our needs.
+ If it is not found then create it and push it into the rendez-vous point */
+ action = SIMIX_rdv_get_request(rdv, SIMIX_COMM_RECEIVE, match_fun, data);
+
+ if (!action) {
+ action = SIMIX_comm_new(SIMIX_COMM_SEND);
+ SIMIX_rdv_push(rdv, action);
+ } else {
+ action->state = SIMIX_READY;
+ action->comm.type = SIMIX_COMM_READY;
+ }
+
+ /* If the communication action is detached then decrease the refcount
+ * by one, so it will be eliminated by the receivers destroy call */
+ if(detached){
+ action->comm.detached = 1;
+ action->comm.refcount--;
+ }
+
+ /* Setup the communication request */
+ action->comm.src_proc = src_proc;
+ action->comm.task_size = task_size;
+ action->comm.rate = rate;
+ action->comm.src_buff = src_buff;
+ action->comm.src_buff_size = src_buff_size;
+ action->comm.src_data = data;
+
+ if (MC_IS_ENABLED) {
+ action->state = SIMIX_RUNNING;
+ return action;
+ }
+
+ SIMIX_comm_start(action);
+ return action;
+}
+
+smx_action_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_rdv_t rdv,
+ void *dst_buff, size_t *dst_buff_size,
+ int (*match_fun)(void *, void *), void *data)
+{
+ smx_action_t action;
+
+ /* Look for communication request matching our needs.
+ * If it is not found then create it and push it into the rendez-vous point