+ DEBUG1
+ ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
+ alias);
+ return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task,
+ host, timeout);
+}
+
+/** \ingroup msg_gos_functions
+ * \brief Sends a task on a mailbox.
+ *
+ * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
+ * to end the communication.
+ *
+ * \param task a #m_task_t to send on another location.
+ * \param alias name of the mailbox to sent the task to
+ * \return the msg_comm_t communication created
+ */
+msg_comm_t MSG_task_isend(m_task_t task, const char *alias)
+{
+ simdata_task_t t_simdata = NULL;
+ m_process_t process = MSG_process_self();
+ msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
+
+ CHECK_HOST();
+
+ /* FIXME: these functions are not traceable */
+
+ /* Prepare the task to send */
+ t_simdata = task->simdata;
+ t_simdata->sender = process;
+ t_simdata->source = MSG_host_self();
+
+ xbt_assert0(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++;
+
+ /* Send it by calling SIMIX network layer */
+ msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
+ comm->task_sent = task;
+ comm->task_received = NULL;
+ comm->status = MSG_OK;
+ comm->s_comm =
+ SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
+ t_simdata->rate, task, sizeof(void *), NULL, NULL, 0);
+ t_simdata->comm = comm->s_comm; /* FIXME: is the field t_simdata->comm still useful? */
+
+ return comm;
+}
+
+/** \ingroup msg_gos_functions
+ * \brief Sends a task on a mailbox.
+ *
+ * This is a non blocking detached send function.
+ * Think of it as a best effort send. The communication
+ * object will be destroyed by the receiver (if any).
+ *
+ * \param task a #m_task_t to send on another location.
+ * \param alias name of the mailbox to sent the task to
+ * \param cleanup a function to destroy the task if the
+ * communication fails (if NULL, MSG_task_destroy() will
+ * be used by default)
+ */
+void MSG_task_dsend(m_task_t task, const char *alias, void_f_pvoid_t cleanup)
+{
+ simdata_task_t t_simdata = NULL;
+ m_process_t process = MSG_process_self();
+ msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
+
+ CHECK_HOST();
+
+ if (cleanup == NULL) {
+ cleanup = (void_f_pvoid_t) MSG_task_destroy;
+ }
+
+ /* FIXME: these functions are not traceable */
+
+ /* Prepare the task to send */
+ t_simdata = task->simdata;
+ t_simdata->sender = process;
+ t_simdata->source = MSG_host_self();
+
+ xbt_assert0(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++;
+
+ /* Send it by calling SIMIX network layer */
+ SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
+ t_simdata->rate, task, sizeof(void *), NULL, cleanup, 1);
+}
+
+/** \ingroup msg_gos_functions
+ * \brief Starts listening for receiving a task from an asynchronous communication.
+ *
+ * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
+ * to end the communication.
+ *
+ * \param task a memory location for storing a #m_task_t.
+ * \param name of the mailbox to receive the task on
+ * \return the msg_comm_t communication created
+ */
+msg_comm_t MSG_task_irecv(m_task_t *task, const char *alias)
+{
+ smx_rdv_t rdv = MSG_mailbox_get_by_alias(alias);
+
+ CHECK_HOST();
+
+ /* FIXME: these functions are not tracable */
+
+ /* Sanity check */
+ xbt_assert0(task, "Null pointer for the task storage");
+
+ if (*task)
+ CRITICAL0
+ ("MSG_task_get() was asked to write in a non empty task struct.");
+
+ /* Try to receive it by calling SIMIX network layer */
+ msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
+ comm->task_sent = NULL;
+ comm->task_received = task;
+ comm->status = MSG_OK;
+ comm->s_comm = SIMIX_req_comm_irecv(rdv, task, NULL, NULL, NULL);
+
+ return comm;
+}
+
+/** \ingroup msg_gos_functions
+ * \brief Checks whether a communication is done, and if yes, finalizes it.
+ * \param comm the communication to test
+ * \return TRUE if the communication is finished
+ * (but it may have failed, use MSG_comm_get_status() to know its status)
+ * or FALSE if the communication is not finished yet
+ * If the status is FALSE, don't forget to use MSG_process_sleep() after the test.
+ */
+int MSG_comm_test(msg_comm_t comm)
+{
+ xbt_ex_t e;
+ int finished = 0;
+ TRY {
+ finished = SIMIX_req_comm_test(comm->s_comm);
+ }
+ CATCH(e) {
+ switch (e.category) {
+
+ case host_error:
+ comm->status = MSG_HOST_FAILURE;
+ finished = 1;
+ break;
+
+ case network_error:
+ comm->status = MSG_TRANSFER_FAILURE;
+ finished = 1;
+ break;
+
+ case timeout_error:
+ comm->status = MSG_TIMEOUT;
+ finished = 1;
+ break;
+
+ default:
+ RETHROW;
+ }
+ xbt_ex_free(e);
+ }
+
+ return finished;
+}
+
+/** \ingroup msg_gos_functions
+ * \brief This function checks if a communication is finished.
+ * \param comms a vector of communications
+ * \return the position of the finished communication if any
+ * (but it may have failed, use MSG_comm_get_status() to know its status),
+ * or -1 if none is finished
+ */
+int MSG_comm_testany(xbt_dynar_t comms)
+{
+ xbt_ex_t e;
+ int finished_index = -1;
+
+ /* create the equivalent dynar with SIMIX objects */
+ xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
+ msg_comm_t comm;
+ unsigned int cursor;
+ xbt_dynar_foreach(comms, cursor, comm) {
+ xbt_dynar_push(s_comms, &comm->s_comm);
+ }
+
+ MSG_error_t status = MSG_OK;
+ TRY {
+ finished_index = SIMIX_req_comm_testany(s_comms);
+ }
+ CATCH(e) {
+ switch (e.category) {
+
+ case host_error:
+ finished_index = e.value;
+ status = MSG_HOST_FAILURE;
+ break;
+
+ case network_error:
+ finished_index = e.value;
+ status = MSG_TRANSFER_FAILURE;
+ break;
+
+ case timeout_error:
+ finished_index = e.value;
+ status = MSG_TIMEOUT;
+ break;
+
+ default:
+ RETHROW;
+ }
+ xbt_ex_free(e);
+ }
+ xbt_dynar_free(&s_comms);
+
+ if (finished_index != -1) {
+ comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
+ /* the communication is finished */
+ comm->status = status;
+ }
+
+ return finished_index;
+}
+
+/** \ingroup msg_gos_functions
+ * \brief Destroys a communication.
+ * \param comm the communication to destroy.
+ */
+void MSG_comm_destroy(msg_comm_t comm)
+{
+ if (comm->task_received != NULL
+ && *comm->task_received != NULL
+ && MSG_comm_get_status(comm) == MSG_OK) {
+ (*comm->task_received)->simdata->isused = 0;
+ }
+
+ /* FIXME auto-destroy comms from SIMIX to avoid this request */
+ /*SIMIX_req_comm_destroy(comm->s_comm);*/
+ free(comm);
+}
+
+/** \ingroup msg_gos_functions
+ * \brief Wait for the completion of a communication.
+ *
+ * It takes two parameters.
+ * \param comm the communication to wait.
+ * \param timeout Wait until the communication terminates or the timeout occurs
+ * \return MSG_error_t
+ */
+MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
+{
+ xbt_ex_t e;
+ TRY {
+ SIMIX_req_comm_wait(comm->s_comm, timeout);
+
+ if (comm->task_received != NULL) {
+ /* I am the receiver */
+ (*comm->task_received)->simdata->isused = 0;
+ }
+
+ /* FIXME: these functions are not traceable */
+ }
+ CATCH(e) {
+ switch (e.category) {
+ case host_error:
+ comm->status = MSG_HOST_FAILURE;
+ break;
+ case network_error:
+ comm->status = MSG_TRANSFER_FAILURE;
+ break;
+ case timeout_error:
+ comm->status = MSG_TIMEOUT;
+ break;
+ default:
+ RETHROW;
+ }
+ xbt_ex_free(e);
+ }
+
+ return comm->status;