- bool restart;
- msg = NULL;
-
- do {
- if (ctrl_comm && comm_test_n_destroy(ctrl_comm)) {
- msg = (message* )MSG_task_get_data(ctrl_task);
- from = MSG_task_get_source(ctrl_task);
- MSG_task_destroy(ctrl_task);
- ctrl_task = NULL;
- ctrl_comm =
- (!ctrl_close_is_last || msg->get_type() != message::CTRL_CLOSE)
- ? ctrl_comm = MSG_task_irecv(&ctrl_task, get_ctrl_mbox())
- : ctrl_comm = NULL;
-
- } else if (data_comm && comm_test_n_destroy(data_comm)) {
- msg = (message* )MSG_task_get_data(data_task);
- from = MSG_task_get_source(data_task);
- MSG_task_destroy(data_task);
- data_task = NULL;
- data_comm =
- (!data_close_is_last || msg->get_type() != message::DATA_CLOSE)
- ? data_comm = MSG_task_irecv(&data_task, get_data_mbox())
- : data_comm = NULL;
- }
-
- restart = wait && !msg && (ctrl_comm || data_comm);
- if (restart) {
- xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
- if (ctrl_comm)
- xbt_dynar_push(comms, &ctrl_comm);
- if (data_comm)
- xbt_dynar_push(comms, &data_comm);
- MSG_comm_waitany(comms);
- xbt_dynar_free(&comms);
- }
- } while (restart);
-
- return msg != NULL;
+ sent_comm_type::iterator bound;
+ bound = std::remove_if(sent_comm.begin(), sent_comm.end(),
+ comm_test_n_destroy);
+ sent_comm.erase(bound, sent_comm.end());
+ if (wait && !sent_comm.empty()) {
+ msg_comm_t comms[sent_comm.size()];
+ std::copy(sent_comm.begin(), sent_comm.end(), comms);
+ MSG_comm_waitall(comms, sent_comm.size(), -1.0);
+ if (!MSG_WAIT_DESTROYS_COMMS)
+ std::for_each(sent_comm.begin(), sent_comm.end(),
+ comm_check_n_destroy);
+ sent_comm.clear();
+ }