- xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
- while (!sent_comm.empty()) {
- std::for_each(sent_comm.begin(), sent_comm.end(),
- std::tr1::bind(xbt_dynar_push,
- comms, std::tr1::placeholders::_1));
- MSG_comm_waitany(comms);
- xbt_dynar_reset(comms);
- flush_sent();
+ using std::tr1::bind;
+ using std::tr1::placeholders::_1;
+
+ sent_comm.remove_if(comm_test_n_destroy);
+ if (wait && !sent_comm.empty()) {
+ xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
+ while (!sent_comm.empty()) {
+ std::for_each(sent_comm.begin(), sent_comm.end(),
+ bind(xbt_dynar_push,
+ comms, bind(misc::address<msg_comm_t>(), _1)));
+ MSG_comm_waitany(comms);
+ xbt_dynar_reset(comms);
+ sent_comm.remove_if(comm_test_n_destroy);
+ }
+ xbt_dynar_free(&comms);