- while(!(task_simdata->comm)) {
- if(max_duration>0) {
- if(!first_time) {
- PAJE_PROCESS_POP_STATE(process);
- PAJE_COMM_STOP(process,task,channel);
- MSG_RETURN(MSG_TRANSFER_FAILURE);
+ SIMIX_mutex_lock(task->simdata->mutex);
+ // DEBUG4("Task sent (%g kB) from %s to %s on channel %d, waiting...", task->simdata->message_size/1000,local_host->name, remote_host->name, channel);
+
+ process->simdata->waiting_task = task;
+ if (max_duration > 0) {
+ xbt_ex_t e;
+ double time;
+ double time_elapsed;
+ time = SIMIX_get_clock();
+ TRY {
+ /*verify if the action that ends is the correct. Call the wait_timeout with the new time. If the timeout occurs, an exception is raised */
+ while (1) {
+ time_elapsed = SIMIX_get_clock() - time;
+ SIMIX_cond_wait_timeout(task->simdata->cond, task->simdata->mutex,
+ max_duration-time_elapsed);
+ if ((task->simdata->comm != NULL) &&
+ (SIMIX_action_get_state(task->simdata->comm) != SURF_ACTION_RUNNING))
+ break;
+ }
+ } CATCH(e) {
+ if(e.category==timeout_error) {
+ xbt_ex_free(e);
+ /* verify if the timeout happened and the communication didn't started yet */
+ if (task->simdata->comm == NULL) {
+ process->simdata->waiting_task = NULL;
+ xbt_fifo_remove(((simdata_host_t) remote_host->simdata)->
+ mbox[channel], task);
+ if (task->simdata->receiver) {
+ task->simdata->receiver->simdata->waiting_task = NULL;
+ }
+ task->simdata->sender = NULL;
+ SIMIX_mutex_unlock(task->simdata->mutex);
+ MSG_RETURN(MSG_TRANSFER_FAILURE);
+ }
+ } else {
+ RETHROW;