-/**
- * \brief Performs error checking and cleanup
- * \param comm The communication
- */
-static XBT_INLINE void SIMIX_communication_cleanup(smx_comm_t comm)
-{
- DEBUG1("Checking errors and cleaning communication %p", comm);
-
- /* Make sure that everyone sleeping on that semaphore is awake, and that nobody will ever block on it */
- SIMIX_sem_release_forever(comm->sem);
-
- /* Check for errors other than timeouts */
- 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");
- } else if (!SIMIX_host_get_state(SIMIX_process_get_host(comm->dst_proc)) ||
- !SIMIX_host_get_state(SIMIX_process_get_host(comm->src_proc))) {
- /* We test both src&dst because we dunno who we are today, and we already tested myself above.
- * So, at the end, we test the remote peer only
- * Moreover, we have to test it because if the remote peer fails, the action comm->act is not done nor failed.
- * In that case, we got awaken by the little endless actions created in the SIMIX_sem_acquire(comm->sem)
- * at the beginning of this function. */
- SIMIX_communication_destroy(comm);
- THROW0(network_error, 0, "Remote peer failed");
-
- }
- /* Copy network data */
- SIMIX_network_copy_data(comm);
-
- SIMIX_communication_destroy(comm);
-}
-
-/**
- * \brief Waits for communication completion
- * \param comm The communication
- * \param timeout The max amount of time to wait for the communication to finish
- *
- * Throws:
- * - host_error if local peer failed
- * - timeout_error if communication reached the timeout specified (either because of local peer or remote peer)
- * - network_error if network failed or remote peer failed
- */
-static XBT_INLINE void SIMIX_communication_wait_for_completion(smx_comm_t comm, double timeout)
-{
- smx_action_t act_sleep = NULL;
- int src_timeout = 0;
- int dst_timeout = 0;
-
- DEBUG1("Waiting for the completion of communication %p", comm);
-
- if (timeout >= 0) {
- act_sleep = SIMIX_action_sleep(SIMIX_host_self(), timeout);
- if(SIMIX_process_self()==comm->src_proc)
- comm->src_timeout = act_sleep;
- else
- comm->dst_timeout = act_sleep;
- SIMIX_action_set_name(act_sleep,bprintf("Timeout for comm %p and wait on semaphore %p (max_duration:%f)", comm, comm->sem,timeout));
- SIMIX_register_action_to_semaphore(act_sleep, comm->sem);
- SIMIX_process_self()->waiting_action = act_sleep;
- SIMIX_sem_block_onto(comm->sem);
- SIMIX_process_self()->waiting_action = NULL;
- SIMIX_unregister_action_to_semaphore(act_sleep, comm->sem);
- } else {
- SIMIX_sem_acquire(comm->sem);
- }
-
- /* Check for timeouts */
- if ((src_timeout = ((comm->src_timeout) && (SIMIX_action_get_state(comm->src_timeout) == SURF_ACTION_DONE))) ||
- (dst_timeout = ((comm->dst_timeout) && (SIMIX_action_get_state(comm->dst_timeout) == SURF_ACTION_DONE))) ) {
- /* Somebody did a timeout! */
- if (src_timeout) DEBUG1("Communication timeout from the src! %p", comm);
- if (dst_timeout) DEBUG1("Communication timeout from the dst! %p", comm);
+void SIMIX_comm_finish(smx_action_t action)
+{
+ unsigned int destroy_count = 0;
+ smx_req_t req;
+
+ while ((req = xbt_fifo_shift(action->request_list))) {
+
+ /* If a waitany request is waiting for this action to finish, then remove
+ it from the other actions in the waitany list. Afterwards, get the
+ position of the actual action in the waitany request's actions dynar and
+ return it as the result of the call */
+ if (req->call == REQ_COMM_WAITANY) {
+ SIMIX_waitany_req_remove_from_actions(req);
+ if (!MC_IS_ENABLED)
+ req->comm_waitany.result = xbt_dynar_search(req->comm_waitany.comms, &action);
+ }