for(auto it = deque->begin(); it != deque->end(); it++){
smx_activity_t synchro = *it;
- simgrid::kernel::activity::Comm *comm = static_cast<simgrid::kernel::activity::Comm*>(synchro);
+ simgrid::kernel::activity::Comm* comm = static_cast<simgrid::kernel::activity::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))) {
+ if (comm->type == type && (!match_fun || match_fun(this_user_data, other_user_data, synchro)) &&
+ (not 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 = static_cast<simgrid::kernel::activity::Comm*>(SIMIX_comm_ref(comm));
+#if SIMGRID_HAVE_MC
comm->mbox_cpy = comm->mbox;
#endif
comm->mbox = nullptr;
simgrid::kernel::activity::Comm* other_comm =
_find_matching_comm(&mbox->comm_queue, SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*remove_matching*/ true);
- if (!other_comm) {
+ if (not other_comm) {
other_comm = this_comm;
if (mbox->permanent_receiver!=nullptr){
//this mailbox is for small messages, which have to be sent right now
other_comm->state = SIMIX_READY;
other_comm->dst_proc=mbox->permanent_receiver.get();
- other_comm->ref();
+ other_comm = static_cast<simgrid::kernel::activity::Comm*>(SIMIX_comm_ref(other_comm));
mbox->done_comm_queue.push_back(other_comm);
XBT_DEBUG("pushing a message into the permanent receive list %p, comm %p", mbox, &(other_comm));
}
} else {
XBT_DEBUG("Receive already pushed");
- this_comm->unref();
+ SIMIX_comm_unref(this_comm);
other_comm->state = SIMIX_READY;
other_comm->type = SIMIX_COMM_READY;
simgrid::kernel::activity::Comm* other_comm;
//communication already done, get it inside the list of completed comms
- if (mbox->permanent_receiver != nullptr && ! mbox->done_comm_queue.empty()) {
+ if (mbox->permanent_receiver != nullptr && not mbox->done_comm_queue.empty()) {
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 list of already received comms
other_comm = _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_comm) {
+ if (not other_comm) {
XBT_DEBUG("We have messages in the permanent receive list, but not the one we are looking for, pushing request into list");
other_comm = this_synchro;
mbox->push(this_synchro);
other_comm->type = SIMIX_COMM_DONE;
other_comm->mbox = nullptr;
}
- other_comm->unref();
- static_cast<simgrid::kernel::activity::Comm*>(this_synchro)->unref();
+ SIMIX_comm_unref(other_comm);
+ SIMIX_comm_unref(this_synchro);
}
} else {
/* Prepare a comm describing us, so that it gets passed to the user-provided filter of other side */
other_comm = _find_matching_comm(&mbox->comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro,
/*remove_matching*/ true);
- if (!other_comm) {
+ if (not other_comm) {
XBT_DEBUG("Receive pushed first %zu", mbox->comm_queue.size());
other_comm = this_synchro;
mbox->push(this_synchro);
} else {
- this_synchro->unref();
+ SIMIX_comm_unref(this_synchro);
+ other_comm = static_cast<simgrid::kernel::activity::Comm*>(other_comm);
other_comm->state = SIMIX_READY;
other_comm->type = SIMIX_COMM_READY;
smx_type = SIMIX_COMM_SEND;
}
smx_activity_t other_synchro=nullptr;
- if (mbox->permanent_receiver != nullptr && !mbox->done_comm_queue.empty()) {
+ if (mbox->permanent_receiver != nullptr && not mbox->done_comm_queue.empty()) {
XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something");
other_synchro = _find_matching_comm(&mbox->done_comm_queue,
(e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false);
}
- if (!other_synchro){
+ if (not other_synchro) {
XBT_DEBUG("check if we have more luck in the normal mailbox");
other_synchro = _find_matching_comm(&mbox->comm_queue,
(e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false);
}
if(other_synchro)
- other_synchro->unref();
+ SIMIX_comm_unref(other_synchro);
- this_comm->unref();
+ SIMIX_comm_unref(this_comm);
return other_synchro;
}
void SIMIX_comm_finish(smx_activity_t synchro)
{
simgrid::kernel::activity::Comm *comm = static_cast<simgrid::kernel::activity::Comm*>(synchro);
- unsigned int destroy_count = 0;
- while (!synchro->simcalls.empty()) {
+ while (not synchro->simcalls.empty()) {
smx_simcall_t simcall = synchro->simcalls.front();
synchro->simcalls.pop_front();
- /* If a waitany simcall is waiting for this synchro to finish, then remove
- it from the other synchros in the waitany list. Afterwards, get the
- position of the actual synchro in the waitany dynar and
- return it as the result of the simcall */
+ /* If a waitany simcall is waiting for this synchro to finish, then remove it from the other synchros in the waitany
+ * list. Afterwards, get the position of the actual synchro in the waitany dynar and return it as the result of the
+ * simcall */
if (simcall->call == SIMCALL_NONE) //FIXME: maybe a better way to handle this case
continue; // if process handling comm is killed
SIMIX_timer_remove(simcall->timer);
simcall->timer = nullptr;
}
- if (!MC_is_active() && !MC_record_replay_is_active())
- simcall_comm_waitany__set__result(simcall, xbt_dynar_search(simcall_comm_waitany__get__comms(simcall), &synchro));
+ if (not MC_is_active() && not MC_record_replay_is_active())
+ simcall_comm_waitany__set__result(simcall,
+ xbt_dynar_search(simcall_comm_waitany__get__comms(simcall), &synchro));
}
/* If the synchro is still in a rendez-vous point then remove from it */
comm->dst_proc->comms.remove(synchro);
comm->src_proc->comms.remove(synchro);
}
- //in case of a detached comm we have an extra ref to remove, as the sender won't do it
- destroy_count++;
}
SIMIX_simcall_answer(simcall);
- destroy_count++;
}
-
- while (destroy_count-- > 0)
- static_cast<simgrid::kernel::activity::Comm*>(synchro)->unref();
}
/******************************************************************************/
}
}
-
/**
* @brief Copy the communication data from the sender's buffer to the receiver's one
* @param synchro The communication
size_t buff_size = comm->src_buff_size;
/* If there is no data to copy then return */
- if (!comm->src_buff || !comm->dst_buff || comm->copied)
+ if (not comm->src_buff || not comm->dst_buff || comm->copied)
return;
XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", comm,
SIMIX_comm_copy_data_callback (comm, comm->src_buff, buff_size);
}
-
/* Set the copied flag so we copy data only once */
/* (this function might be called from both communication ends) */
comm->copied = 1;
}
+
+/** Increase the refcount for this comm */
+smx_activity_t SIMIX_comm_ref(smx_activity_t comm)
+{
+ if (comm != nullptr)
+ intrusive_ptr_add_ref(comm);
+ return comm;
+}
+
+/** Decrease the refcount for this comm */
+void SIMIX_comm_unref(smx_activity_t comm)
+{
+ if (comm != nullptr)
+ intrusive_ptr_release(comm);
+}