+void process::ctrl_send(neighbor& nb)
+{
+ double info_to_send = get_load();
+ if (info_to_send != prev_load_broadcast)
+ comm.ctrl_send(nb.get_ctrl_mbox(),
+ new message(message::INFO, info_to_send));
+ if (opt::bookkeeping) {
+ double debt_to_send = nb.get_to_send();
+ if (debt_to_send > 0.0) {
+ nb.set_to_send(0.0);
+ nb.set_debt(nb.get_debt() + debt_to_send);
+ comm.ctrl_send(nb.get_ctrl_mbox(),
+ new message(message::CREDIT, debt_to_send));
+ }
+ }
+}
+
+void process::data_send(neighbor& nb)
+{
+ double load_to_send;
+ if (opt::bookkeeping) {
+ if (real_load <= nb.get_debt()) {
+ load_to_send = real_load;
+ nb.set_debt(nb.get_debt() - load_to_send);
+ real_load = 0.0;
+ } else {
+ load_to_send = nb.get_debt();
+ nb.set_debt(0.0);
+ real_load -= load_to_send;
+ }
+ } else {
+ load_to_send = nb.get_to_send();
+ nb.set_to_send(0.0);
+ }
+ if (load_to_send > 0.0)
+ comm.data_send(nb.get_data_mbox(),
+ new message(message::LOAD, load_to_send));
+}
+
+void process::ctrl_close(neighbor& nb)
+{
+ comm.ctrl_send(nb.get_ctrl_mbox(), new message(message::CTRL_CLOSE, 0.0));
+}
+
+void process::data_close(neighbor& nb)
+{
+ comm.data_send(nb.get_data_mbox(), new message(message::DATA_CLOSE, 0.0));
+}
+
+void process::ctrl_receive(double timeout)
+{
+ message* msg;
+ m_host_t from;
+
+ XBT_DEBUG("%sblocking receive on ctrl (%g)", "\0non-" + !timeout, timeout);
+ while (ctrl_close_pending && comm.ctrl_recv(msg, from, timeout)) {
+ handle_message(msg, from);
+ timeout = 0.0;
+ }
+}
+
+void process::data_receive(double timeout)
+{
+ message* msg;
+ m_host_t from;
+
+ XBT_DEBUG("%sblocking receive on data (%g)", "\0non-" + !timeout, timeout);
+ while (data_close_pending && comm.data_recv(msg, from, timeout)) {
+ handle_message(msg, from);
+ timeout = 0.0;
+ }
+}
+
+void process::handle_message(message* msg, m_host_t from)
+{
+ switch (msg->get_type()) {
+ case message::INFO: {
+ neighbor* n = rev_neigh[from];
+ n->set_load(msg->get_amount());
+ break;
+ }
+ case message::CREDIT:
+ expected_load += msg->get_amount();
+ break;
+ case message::LOAD: {
+ double ld = msg->get_amount();
+ real_load += ld;
+ if (finalizing)
+ total_load_running -= ld;
+ break;
+ }
+ case message::CTRL_CLOSE:
+ ctrl_close_pending--;
+ close_received = true;
+ break;
+ case message::DATA_CLOSE:
+ data_close_pending--;
+ close_received = true;
+ break;
+ }
+ delete msg;
+}
+