4 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(comm);
11 message::message(message_type t, double a, double c)
12 : type(t), amount(a) , credit(c)
14 // compute message size
15 // arbitrary: 8 for type, and 8 for each double
18 size = opt::bookkeeping ? 24 : 16; // type + amount + (credit)?
21 size = 16 + opt::comm_cost(amount); // type + amount + data size
29 std::string message::to_string()
31 static const char* str[DATA_CLOSE + 1] = { "CTRL", "DATA",
32 "CTRL_CLOSE", "DATA_CLOSE" };
33 std::ostringstream oss;
34 oss << str[type] << ": " << amount;
38 void message_queue::push(m_task_t task)
40 if (queue.push(task)) {
41 // list was empty, the push must be signaled
48 bool message_queue::pop(message*& msg, m_host_t& from, double timeout)
51 if (!queue.try_pop(task)) {
56 if (!queue.try_pop(task)) {
58 XBT_DEBUG("waiting for a message to come");
61 cond.timedwait(mutex, timeout);
69 if (e.category != timeout_error)
72 return false; // got a timeout
74 bool pop_was_successful = queue.try_pop(task);
75 xbt_assert(pop_was_successful);
80 msg = static_cast<message*>(MSG_task_get_data(task));
81 from = MSG_task_get_source(task);
82 MSG_task_destroy(task);
84 XBT_DEBUG("received %s from %s",
85 msg->to_string().c_str(), MSG_host_get_name(from));