X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/59a1cb7b07e16f70c90ac11398fde26a52f749e4..cd1b6fc186f641dd5e3fb68d793c6253e1b8fcd9:/src/simix/smx_network.cpp diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 36da57293f..724dc20202 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -20,9 +20,8 @@ static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall); static void SIMIX_comm_copy_data(smx_synchro_t comm); static smx_synchro_t SIMIX_comm_new(e_smx_comm_type_t type); static inline void SIMIX_mbox_push(smx_mailbox_t mbox, smx_synchro_t comm); -static smx_synchro_t _extract_matching_comm(std::deque *deque, e_smx_comm_type_t type, - int (*match_fun)(void *, void *,smx_synchro_t), - void *user_data, smx_synchro_t my_synchro); +static smx_synchro_t _find_matching_comm(std::deque *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) @@ -42,13 +41,12 @@ smx_mailbox_t SIMIX_mbox_create(const char *name) if (!mbox) { mbox = xbt_new0(s_smx_mailbox_t, 1); - mbox->name = xbt_strdup(name); mbox->comm_queue = new std::deque(); 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); + xbt_dict_set(mailboxes, name, mbox, NULL); } return mbox; } @@ -57,7 +55,6 @@ 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; @@ -71,7 +68,7 @@ smx_mailbox_t SIMIX_mbox_get_by_name(const char *name) smx_synchro_t SIMIX_mbox_get_head(smx_mailbox_t mbox) { - return mbox->comm_queue->front(); + return mbox->comm_queue->empty()? nullptr:mbox->comm_queue->front(); } /** @@ -128,8 +125,8 @@ void SIMIX_mbox_remove(smx_mailbox_t mbox, smx_synchro_t comm) * \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 _extract_matching_comm(std::deque *deque, e_smx_comm_type_t type, - int (*match_fun)(void *, void *,smx_synchro_t), void *this_user_data, smx_synchro_t my_synchro) +static smx_synchro_t _find_matching_comm(std::deque *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; @@ -144,7 +141,8 @@ static smx_synchro_t _extract_matching_comm(std::deque *deque, e_ (!match_fun || match_fun(this_user_data, other_user_data, synchro)) && (!synchro->comm.match_fun || synchro->comm.match_fun(other_user_data, this_user_data, my_synchro))) { XBT_DEBUG("Found a matching communication synchro %p", synchro); - deque->erase(it); + if (remove_matching) + deque->erase(it); synchro->comm.refcount++; #if HAVE_MC synchro->comm.mbox_cpy = synchro->comm.mbox; @@ -277,7 +275,8 @@ smx_synchro_t simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_process_t sr * ourself so that the other side also gets a chance of choosing if it wants to match with us. * * If it is not found then push our communication into the rendez-vous point */ - smx_synchro_t other_synchro = _extract_matching_comm(mbox->comm_queue, SIMIX_COMM_RECEIVE, match_fun, data, this_synchro); + smx_synchro_t other_synchro = + _find_matching_comm(mbox->comm_queue, SIMIX_COMM_RECEIVE, match_fun, data, this_synchro, /*remove_matching*/true); if (!other_synchro) { other_synchro = this_synchro; @@ -371,7 +370,7 @@ smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox, void XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication"); //find a match in the already received fifo - other_synchro = _extract_matching_comm(mbox->done_comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro); + other_synchro = _find_matching_comm(mbox->done_comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro,/*remove_matching*/true); //if not found, assume the receiver came first, register it to the mailbox in the classical way if (!other_synchro) { XBT_DEBUG("We have messages in the permanent receive list, but not the one we are looking for, pushing request into fifo"); @@ -394,7 +393,7 @@ smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox, void * ourself so that the other side also gets a chance of choosing if it wants to match with us. * * If it is not found then push our communication into the rendez-vous point */ - other_synchro = _extract_matching_comm(mbox->comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro); + other_synchro = _find_matching_comm(mbox->comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro,/*remove_matching*/true); if (!other_synchro) { XBT_DEBUG("Receive pushed first %zu", mbox->comm_queue->size()); @@ -453,11 +452,13 @@ smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int smx_synchro_t other_synchro=NULL; if(mbox->permanent_receiver && ! mbox->done_comm_queue->empty()){ XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something"); - other_synchro = _extract_matching_comm(mbox->done_comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_synchro); + other_synchro = + _find_matching_comm(mbox->done_comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_synchro,/*remove_matching*/false); } if (!other_synchro){ XBT_DEBUG("check if we have more luck in the normal mailbox"); - other_synchro = _extract_matching_comm(mbox->comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_synchro); + other_synchro = + _find_matching_comm(mbox->comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_synchro,/*remove_matching*/false); } if(other_synchro) other_synchro->comm.refcount--;