+
+/**
+ * @brief Checks if there is a communication activity queued in comm_queue_ matching our needs
+ * @param type The type of communication we are looking for (comm_send, comm_recv)
+ * @param match_fun the function to apply
+ * @param this_user_data additional parameter to the match_fun
+ * @param my_synchro what to compare against
+ * @param remove_matching whether or not to clean the found object from the queue
+ * @return The communication activity if found, nullptr otherwise
+ */
+CommImplPtr MailboxImpl::find_matching_comm(CommImplType type,
+ const std::function<bool(void*, void*, CommImpl*)>& match_fun,
+ void* this_user_data, const CommImplPtr& my_synchro, bool done,
+ bool remove_matching)
+{
+ auto& comm_queue = done ? done_comm_queue_ : comm_queue_;
+
+ auto iter = std::find_if(
+ comm_queue.begin(), comm_queue.end(), [&type, &match_fun, &this_user_data, &my_synchro](const CommImplPtr& comm) {
+ void* other_user_data = (comm->get_type() == CommImplType::SEND ? comm->src_data_ : comm->dst_data_);
+ return (comm->get_type() == type && (not match_fun || match_fun(this_user_data, other_user_data, comm.get())) &&
+ (not comm->match_fun || comm->match_fun(other_user_data, this_user_data, my_synchro.get())));
+ });
+ if (iter == comm_queue.end()) {
+ XBT_DEBUG("No matching communication synchro found");
+ return nullptr;
+ }
+
+ const CommImplPtr& comm = *iter;
+ XBT_DEBUG("Found a matching communication synchro %p", comm.get());
+ comm->set_mailbox(nullptr);
+ CommImplPtr comm_cpy = comm;
+ if (remove_matching)
+ comm_queue.erase(iter);
+ return comm_cpy;