-static void SIMIX_comm_copy_data(smx_synchro_t comm);
-static inline void SIMIX_mbox_push(smx_mailbox_t mbox, smx_synchro_t comm);
-static smx_synchro_t _find_matching_comm(std::deque<smx_synchro_t> *deque, e_smx_comm_type_t type,
- int (*match_fun)(void *, void *,smx_synchro_t), void *user_data, smx_synchro_t my_synchro, bool remove_matching);
-static void SIMIX_comm_start(smx_synchro_t synchro);
-
-void SIMIX_mailbox_exit(void)
-{
- xbt_dict_free(&mailboxes);
-}
-
-/******************************************************************************/
-/* Rendez-Vous Points */
-/******************************************************************************/
-
-smx_mailbox_t SIMIX_mbox_create(const char *name)
-{
- xbt_assert(name, "Mailboxes must have a name");
- /* two processes may have pushed the same mbox_create simcall at the same time */
- smx_mailbox_t mbox = (smx_mailbox_t) xbt_dict_get_or_null(mailboxes, name);
-
- if (!mbox) {
- mbox = xbt_new0(s_smx_mailbox_t, 1);
- mbox->name = xbt_strdup(name);
- mbox->comm_queue = new std::deque<smx_synchro_t>();
- mbox->done_comm_queue = nullptr; // Allocated on need only
- mbox->permanent_receiver=NULL;
-
- XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name);
- xbt_dict_set(mailboxes, mbox->name, mbox, NULL);
- }
- return mbox;
-}
-
-void SIMIX_mbox_free(void *data)
-{
- XBT_DEBUG("mbox free %p", data);
- smx_mailbox_t mbox = (smx_mailbox_t) data;
- xbt_free(mbox->name);
- delete mbox->comm_queue;
- delete mbox->done_comm_queue;
-
- xbt_free(mbox);
-}
-
-smx_mailbox_t SIMIX_mbox_get_by_name(const char *name)
-{
- return (smx_mailbox_t) xbt_dict_get_or_null(mailboxes, name);
-}
-
-/**
- * \brief set the receiver of the rendez vous point to allow eager sends
- * \param mbox The rendez-vous point
- * \param process The receiving process
- */
-void SIMIX_mbox_set_receiver(smx_mailbox_t mbox, smx_process_t process)
-{
- mbox->permanent_receiver=process;
- if (mbox->done_comm_queue == nullptr)
- mbox->done_comm_queue = new std::deque<smx_synchro_t>();
-}
-
-/**
- * \brief Pushes a communication synchro into a rendez-vous point
- * \param mbox The mailbox
- * \param comm The communication synchro
- */
-static inline void SIMIX_mbox_push(smx_mailbox_t mbox, smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- mbox->comm_queue->push_back(comm);
- comm->mbox = mbox;
-}
-
-/**
- * \brief Removes a communication synchro from a rendez-vous point
- * \param mbox The rendez-vous point
- * \param comm The communication synchro
- */
-void SIMIX_mbox_remove(smx_mailbox_t mbox, smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- comm->mbox = NULL;
- for (auto it = mbox->comm_queue->begin(); it != mbox->comm_queue->end(); it++)
- if (*it == comm) {
- mbox->comm_queue->erase(it);
- return;
- }
- xbt_die("Cannot remove this comm that is not part of the mailbox");
-}
-
-/**
- * \brief Checks if there is a communication synchro queued in a deque matching our needs
- * \param type The type of communication we are looking for (comm_send, comm_recv)
- * \return The communication synchro if found, NULL otherwise
- */
-static smx_synchro_t _find_matching_comm(std::deque<smx_synchro_t> *deque, e_smx_comm_type_t type,
- int (*match_fun)(void *, void *,smx_synchro_t), void *this_user_data, smx_synchro_t my_synchro, bool remove_matching)
-{
- void* other_user_data = NULL;
-
- for(auto it = deque->begin(); it != deque->end(); it++){
- smx_synchro_t synchro = *it;
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- if (comm->type == SIMIX_COMM_SEND) {
- other_user_data = comm->src_data;
- } else if (comm->type == SIMIX_COMM_RECEIVE) {
- other_user_data = comm->dst_data;
- }
- if (comm->type == type &&
- (! match_fun || match_fun(this_user_data, other_user_data, synchro)) &&
- (!comm->match_fun || comm->match_fun(other_user_data, this_user_data, my_synchro))) {
- XBT_DEBUG("Found a matching communication synchro %p", comm);
- if (remove_matching)
- deque->erase(it);
- comm->ref();
-#if HAVE_MC
- comm->mbox_cpy = comm->mbox;
-#endif
- comm->mbox = NULL;
- return comm;
- }
- XBT_DEBUG("Sorry, communication synchro %p does not match our needs:"
- " its type is %d but we are looking for a comm of type %d (or maybe the filtering didn't match)",
- comm, (int)comm->type, (int)type);
- }
- XBT_DEBUG("No matching communication synchro found");
- return NULL;
-}