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
17 case message_type::CTRL:
18 size = opt::bookkeeping ? 24 : 16; // type + amount + (credit)?
20 case message_type::DATA:
21 size = 16 + opt::comm_cost(amount); // type + amount + data size
29 std::string message::to_string()
31 std::ostringstream oss;
33 case message_type::CTRL:
34 oss << "CTRL: " << amount << " (info)";
36 oss << "; " << credit << " (credit)";
38 case message_type::DATA:
39 oss << "DATA: " << amount << " (load)";
41 case message_type::CTRL_CLOSE:
44 case message_type::DATA_CLOSE:
48 oss << "UNKNOWN MESSAGE TYPE: " << static_cast<int>(type);
54 void message_queue::push(msg_task_t task)
56 if (queue.push(task)) {
57 // list was empty, the push must be signaled
64 bool message_queue::pop(message*& msg, msg_host_t& from, double timeout)
66 msg_task_t task = nullptr;
67 if (!queue.try_pop(task)) {
72 if (!queue.try_pop(task)) {
73 XBT_DEBUG("waiting for a message to come");
76 hit_timeout = !cond.timedwait(mutex, timeout);
81 bool pop_was_successful = queue.try_pop(task);
82 xbt_assert(hit_timeout || pop_was_successful);
89 msg = static_cast<message*>(MSG_task_get_data(task));
90 from = MSG_task_get_source(task);
91 MSG_task_destroy(task);
93 XBT_DEBUG("received %s from %s",
94 msg->to_string().c_str(), MSG_host_get_name(from));