- xbt_assert1((channel >= 0)
- && (channel < msg_global->max_channel), "Invalid channel %d",
- channel);
-
- task_simdata = task->simdata;
- task_simdata->sender = process;
- task_simdata->source = MSG_process_get_host(process);
- xbt_assert0(task_simdata->using == 1,
- "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
- task_simdata->comm = NULL;
-
- task_simdata->using++;
- local_host = ((simdata_process_t) process->simdata)->m_host;
- remote_host = dest;
-
- DEBUG4("Trying to send a task (%g kB) from %s to %s on channel %d",
- task->simdata->message_size / 1000, local_host->name,
- remote_host->name, channel);
-
- SIMIX_mutex_lock(remote_host->simdata->mutex);
- xbt_fifo_push(((simdata_host_t) remote_host->simdata)->
- mbox[channel], task);
-
-
- if (remote_host->simdata->sleeping[channel]) {
- DEBUG0("Somebody is listening. Let's wake him up!");
- SIMIX_cond_signal(remote_host->simdata->sleeping[channel]);
- }
- SIMIX_mutex_unlock(remote_host->simdata->mutex);
-
- process->simdata->put_host = dest;
- process->simdata->put_channel = channel;
- 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;
- }
- }
- } else {
- while (1) {
- SIMIX_cond_wait(task->simdata->cond, task->simdata->mutex);
- if (SIMIX_action_get_state(task->simdata->comm) != SURF_ACTION_RUNNING)
- break;
- }
- }
-
- DEBUG1("Action terminated %s", task->name);
- process->simdata->waiting_task = NULL;
- /* the task has already finished and the pointer must be null */
- if (task->simdata->receiver) {
- task->simdata->receiver->simdata->waiting_task = NULL;
- /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
- // task->simdata->comm = NULL;
- //task->simdata->compute = NULL;
- }
- task->simdata->sender = NULL;
- SIMIX_mutex_unlock(task->simdata->mutex);
-
- if (SIMIX_action_get_state(task->simdata->comm) == SURF_ACTION_DONE) {
- MSG_RETURN(MSG_OK);
- } else if (SIMIX_host_get_state(local_host->simdata->smx_host) == 0) {
- MSG_RETURN(MSG_HOST_FAILURE);
- } else {
- MSG_RETURN(MSG_TRANSFER_FAILURE);
- }