- if (data_comm && comm_test_n_destroy(data_comm)) {
- if (strcmp(MSG_task_get_name(data_task), "finalize")) {
- XBT_DEBUG("received message from data");
- xbt_mutex_acquire(mutex);
- received.push(data_task);
- xbt_mutex_release(mutex);
- data_task = NULL;
- data_comm = MSG_task_irecv(&data_task, get_data_mbox());
- } else {
- XBT_DEBUG("received finalize from data");
- MSG_task_destroy(data_task);
- data_task = NULL;
- data_comm = NULL;
- }
+ 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);
+ } else {
+ XBT_DEBUG("received finalize on %s", ch->mbox);
+ MSG_task_destroy(ch->task);
+ ch->task = NULL;
+ ch->comm = NULL;
+ xbt_dynar_remove_at(comms, index, NULL);