- task_simdata = task->simdata;
- task_simdata->sender = process;
- task_simdata->source = MSG_process_get_host(process);
-
- xbt_assert0(task_simdata->refcount == 1,
- "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
-
- task_simdata->comm = NULL;
-
- task_simdata->refcount ++;
- local_host = ((simdata_process_t) process->simdata)->m_host;
-
- /* get the host name containing the mailbox */
- hostname = MSG_mailbox_get_hostname(mailbox);
-
- remote_host = MSG_get_host_by_name(hostname);
-
- if (!remote_host)
- THROW1(not_found_error, 0, "Host %s not fount", hostname);
-
-
- DEBUG4
- ("Trying to send a task (%g kB) from %s to %s on the channel aliased by the alias %s",
- task->simdata->message_size / 1000, local_host->name,
- remote_host->name, MSG_mailbox_get_alias(mailbox));
-
- SIMIX_mutex_lock(remote_host->simdata->mutex);
-
- /* put the task in the mailbox */
- MSG_mailbox_put(mailbox, task);
-
- if ((cond = MSG_mailbox_get_cond(mailbox))) {
- DEBUG0("Somebody is listening. Let's wake him up!");
- SIMIX_cond_signal(cond);
- }
-
- SIMIX_mutex_unlock(remote_host->simdata->mutex);
-
- SIMIX_mutex_lock(task->simdata->mutex);
-
- process->simdata->waiting_task = task;
-
- if (timeout > 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,
- timeout - 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;
-
- /* remove the task from the mailbox */
- MSG_mailbox_remove(mailbox, 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;
+#ifdef HAVE_TRACING
+ int call_end = TRACE_msg_task_put_start(task); //must be after CHECK_HOST()
+#endif
+
+ /* Prepare the task to send */
+ t_simdata = task->simdata;
+ t_simdata->sender = process;
+ t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
+
+ xbt_assert(t_simdata->isused == 0,
+ "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
+
+ t_simdata->isused=1;
+ msg_global->sent_msg++;
+
+
+ p_simdata->waiting_task = task;
+
+ /* Try to send it by calling SIMIX network layer */
+ TRY {
+#ifdef HAVE_TRACING
+ if (TRACE_is_enabled()) {
+ smx_action_t comm = SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
+ t_simdata->rate, task, sizeof(void *),
+ NULL, NULL, 0);
+ SIMIX_req_set_category(comm, task->category);
+ SIMIX_req_comm_wait(comm, timeout);
+ } else {
+#endif
+ SIMIX_req_comm_send(mailbox, t_simdata->message_size,
+ t_simdata->rate, task, sizeof(void*),
+ NULL, NULL, timeout);
+#ifdef HAVE_TRACING