3 /* Copyright (c) 2008-2015. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #include "simgrid/msg.h"
12 #include "msg_private.h"
13 #include "simgrid/s4u/mailbox.hpp"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_mailbox, msg, "Logging specific to MSG (mailbox)");
17 /** \ingroup msg_mailbox_management
18 * \brief Set the mailbox to receive in asynchronous mode
20 * All messages sent to this mailbox will be transferred to the receiver without waiting for the receive call.
21 * The receive call will still be necessary to use the received data.
22 * If there is a need to receive some messages asynchronously, and some not, two different mailboxes should be used.
24 * \param alias The name of the mailbox
26 void MSG_mailbox_set_async(const char *alias){
27 simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(alias);
29 simcall_mbox_set_receiver(mailbox->getImpl(), SIMIX_process_self());
30 XBT_VERB("%s mailbox set to receive eagerly for myself\n",alias);
33 /** \ingroup msg_mailbox_management
34 * \brief Get a task from a mailbox on a given host at a given rate
36 * \param mailbox The mailbox where the task was sent
37 * \param task a memory location for storing a #msg_task_t.
38 * \param host a #msg_host_t host from where the task was sent
39 * \param timeout a timeout
43 * #MSG_OK if the task was successfully received,
44 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
46 msg_error_t MSG_mailbox_get_task_ext_bounded(msg_mailbox_t mailbox, msg_task_t * task, msg_host_t host, double timeout,
49 msg_error_t ret = MSG_OK;
50 /* We no longer support getting a task from a specific host */
54 TRACE_msg_task_get_start();
55 double start_time = MSG_get_clock();
58 xbt_assert(task, "Null pointer for the task storage");
61 XBT_WARN("Asked to write the received task in a non empty struct -- proceeding.");
63 /* Try to receive it by calling SIMIX network layer */
65 simcall_comm_recv(MSG_process_self(), mailbox->getImpl(), task, nullptr, nullptr, nullptr, nullptr, timeout, rate);
66 XBT_DEBUG("Got task %s from %s",(*task)->name,mailbox->getName());
67 (*task)->simdata->setNotUsed();
72 ret = MSG_HOST_FAILURE;
75 ret = MSG_TRANSFER_FAILURE;
81 ret = MSG_HOST_FAILURE;
88 if (ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) {
89 TRACE_msg_task_get_end(start_time, *task);