-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");
+ xbt_mutex_acquire(receiver_mutex);
+ xbt_cond_signal(receiver_cond); // signal master that we are ready
+ xbt_mutex_release(receiver_mutex);
+
+ 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);
+ xbt_mutex_acquire(receiver_mutex);
+ received.push(ch->task);
+ xbt_cond_signal(receiver_cond);
+ xbt_mutex_release(receiver_mutex);
+ ch->task = NULL;
+ ch->comm = MSG_task_irecv(&ch->task, ch->mbox);
+ xbt_dynar_set_as(comms, index, msg_comm_t, ch->comm);