5 #include "communicator.h"
7 // XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(comm, simu,
9 "Messages from asynchronous pipes");
12 bool comm_test_n_destroy(msg_comm_t& comm)
14 if (MSG_comm_test(comm)) {
15 MSG_comm_destroy(comm);
22 communicator::communicator()
24 const char* hostname = MSG_host_get_name(MSG_host_self());
25 size_t len = std::strlen(hostname);
26 recv_mbox = new char[len + 1];
27 strcpy(recv_mbox, hostname);
29 recv_comm = MSG_task_irecv(&recv_task, recv_mbox);
32 communicator::~communicator()
35 if (!sent_comm.empty())
36 WARN1("Lost %ld send communications!", (long )sent_comm.size());
41 void communicator::send(m_task_t task, const char *dest)
43 sent_comm.push_back(MSG_task_isend(task, dest));
47 void communicator::send(m_task_t task, const std::string& dest)
49 send(task, dest.c_str());
52 m_task_t communicator::recv()
55 if (comm_test_n_destroy(recv_comm)) {
58 recv_comm = MSG_task_irecv(&recv_task, recv_mbox);
63 int communicator::sent_count()
66 return sent_comm.size();
69 void communicator::send_acknowledge()
71 std::remove_if(sent_comm.begin(), sent_comm.end(), comm_test_n_destroy);