-bool communicator::recv_ctrl(message_type type, double& amount, m_host_t& from)
-{
- bool res = MSG_comm_test(ctrl_comm);
- if (res) {
- message* msg = (message* )MSG_task_get_data(ctrl_task);
- if (msg->type == type) {
- MSG_comm_destroy(ctrl_comm);
- amount = msg->amount;
- from = MSG_task_get_source(ctrl_task);
- delete msg;
- MSG_task_destroy(ctrl_task);
- ctrl_task = NULL;
- ctrl_comm = MSG_task_irecv(&ctrl_task, ctrl_mbox);
+ XBT_DEBUG("receiver ready");
+ receiver_mutex.acquire();
+ receiver_cond.signal(); // signal master that we are ready
+ receiver_mutex.release();
+
+ while (!xbt_dynar_is_empty(comms)) {
+
+ int index = MSG_comm_waitany(comms);
+ msg_comm_t finished_comm = xbt_dynar_get_as(comms, index, msg_comm_t);
+ channel* ch;
+
+ for (ch = chan ; ch->comm != finished_comm ; ++ch)
+ /* nop */;
+
+ comm_check_n_destroy(ch->comm);
+ if (strcmp(MSG_task_get_name(ch->task), "finalize")) {
+ XBT_DEBUG("received message on %s", ch->mbox);
+ receiver_mutex.acquire();
+ received.push(ch->task);
+ receiver_cond.signal();
+ receiver_mutex.release();
+ ch->task = NULL;
+ ch->comm = MSG_task_irecv(&ch->task, ch->mbox);
+ xbt_dynar_set_as(comms, index, msg_comm_t, ch->comm);