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 _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);
return (smx_mailbox_t) xbt_dict_get_or_null(mailboxes, name);
}
-smx_synchro_t SIMIX_mbox_get_head(smx_mailbox_t mbox)
-{
- return mbox->comm_queue->empty()? nullptr:mbox->comm_queue->front();
-}
-
-/**
- * \brief get the receiver (process associated to the mailbox)
- * \param mbox The rendez-vous point
- * \return process The receiving process (NULL if not set)
- */
-smx_process_t SIMIX_mbox_get_receiver(smx_mailbox_t mbox)
-{
- return mbox->permanent_receiver;
-}
-
/**
* \brief set the receiver of the rendez vous point to allow eager sends
* \param mbox The rendez-vous point
/* Communication synchros */
/******************************************************************************/
-/**
- * \brief Creates a new communicate synchro
- * \param type The direction of communication (comm_send, comm_recv)
- * \return The new communicate synchro
- */
-smx_synchro_t SIMIX_comm_new(e_smx_comm_type_t type)
-{
- simgrid::simix::Comm *comm = new simgrid::simix::Comm();
- comm->state = SIMIX_WAITING;
- comm->type = type;
- comm->refcount = 1;
- comm->src_data=NULL;
- comm->dst_data=NULL;
-
- XBT_DEBUG("Create communicate synchro %p", comm);
-
- return comm;
-}
-
/**
* \brief Destroy a communicate synchro
* \param synchro The communicate synchro to be destroyed
if (comm->refcount <= 0) {
xbt_backtrace_display_current();
- xbt_die("The refcount of comm %p is already 0 before decreasing it. "
- "That's a bug! If you didn't test and/or wait the same communication twice in your code, then the bug is SimGrid's...", synchro);
+ xbt_die("This comm has a negative refcount! You must not call test() or wait() more than once on a given communication.");
}
comm->refcount--;
if (comm->refcount > 0)
return;
XBT_DEBUG("Really free communication %p; refcount is now %d", comm, comm->refcount);
- SIMIX_comm_destroy_internal_actions(synchro);
+ comm->cleanupSurf();
if (comm->detached && comm->state != SIMIX_DONE) {
/* the communication has failed and was detached:
delete comm;
}
-void SIMIX_comm_destroy_internal_actions(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
- if (comm->surf_comm){
- comm->surf_comm->unref();
- comm->surf_comm = NULL;
- }
-
- if (comm->src_timeout){
- comm->src_timeout->unref();
- comm->src_timeout = NULL;
- }
-
- if (comm->dst_timeout){
- comm->dst_timeout->unref();
- comm->dst_timeout = NULL;
- }
-}
-
void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_process_t src, smx_mailbox_t mbox,
double task_size, double rate,
void *src_buff, size_t src_buff_size,
XBT_DEBUG("send from %p", mbox);
/* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
- smx_synchro_t this_synchro = SIMIX_comm_new(SIMIX_COMM_SEND);
+ smx_synchro_t this_synchro = new simgrid::simix::Comm(SIMIX_COMM_SEND);
/* Look for communication synchro matching our needs. We also provide a description of
* ourself so that the other side also gets a chance of choosing if it wants to match with us.
void *data, double rate)
{
XBT_DEBUG("recv from %p %p", mbox, mbox->comm_queue);
- smx_synchro_t this_synchro = SIMIX_comm_new(SIMIX_COMM_RECEIVE);
+ smx_synchro_t this_synchro = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
smx_synchro_t other_synchro;
//communication already done, get it inside the fifo of completed comms
} else {
simgrid::simix::Comm *other_comm = static_cast<simgrid::simix::Comm*>(other_synchro);
- if(other_comm->surf_comm && SIMIX_comm_get_remains(other_comm)==0.0) {
+ if(other_comm->surf_comm && other_comm->remains()==0.0) {
XBT_DEBUG("comm %p has been already sent, and is finished, destroy it",other_comm);
other_comm->state = SIMIX_DONE;
other_comm->type = SIMIX_COMM_DONE;
smx_synchro_t this_synchro;
int smx_type;
if(type == 1){
- this_synchro=SIMIX_comm_new(SIMIX_COMM_SEND);
+ this_synchro = new simgrid::simix::Comm(SIMIX_COMM_SEND);
smx_type = SIMIX_COMM_RECEIVE;
} else{
- this_synchro=SIMIX_comm_new(SIMIX_COMM_RECEIVE);
+ this_synchro = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
smx_type = SIMIX_COMM_SEND;
}
smx_synchro_t other_synchro=NULL;
void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_synchro_t synchro, double timeout)
{
- /* the simcall may be a wait, a send or a recv */
- surf_action_t sleep;
-
/* Associate this simcall to the wait synchro */
XBT_DEBUG("simcall_HANDLER_comm_wait, %p", synchro);
if (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING) {
SIMIX_comm_finish(synchro);
} else { /* if (timeout >= 0) { we need a surf sleep action even when there is no timeout, otherwise surf won't tell us when the host fails */
- sleep = surf_host_sleep(simcall->issuer->host, timeout);
+ surf_action_t sleep = surf_host_sleep(simcall->issuer->host, timeout);
sleep->setData(synchro);
simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
{
simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
- if(MC_is_active() || MC_record_replay_is_active()){
+ if (MC_is_active() || MC_record_replay_is_active()){
simcall_comm_test__set__result(simcall, comm->src_proc && comm->dst_proc);
- if(simcall_comm_test__get__result(simcall)){
+ if (simcall_comm_test__get__result(simcall)){
synchro->state = SIMIX_DONE;
xbt_fifo_push(synchro->simcalls, simcall);
SIMIX_comm_finish(synchro);
- }else{
+ } else {
SIMIX_simcall_answer(simcall);
}
return;
unsigned int cursor = 0;
xbt_dynar_t synchros = simcall_comm_waitany__get__comms(simcall);
- xbt_dynar_foreach(synchros, cursor, synchro) {
+ xbt_dynar_foreach(synchros, cursor, synchro)
xbt_fifo_remove(synchro->simcalls, simcall);
- }
}
/**
XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure",
sg_host_get_name(sender), sg_host_get_name(receiver));
comm->state = SIMIX_LINK_FAILURE;
- SIMIX_comm_destroy_internal_actions(synchro);
+ comm->cleanupSurf();
}
/* If any of the process is suspend, create the synchro but stop its execution,
comm, (int)comm->state, comm->src_proc, comm->dst_proc, comm->detached);
/* destroy the surf actions associated with the Simix communication */
- SIMIX_comm_destroy_internal_actions(comm);
+ comm->cleanupSurf();
/* if there are simcalls associated with the synchro, then answer them */
if (xbt_fifo_size(synchro->simcalls)) {
}
}
-void SIMIX_comm_cancel(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- /* if the synchro is a waiting state means that it is still in a mbox */
- /* so remove from it and delete it */
- if (comm->state == SIMIX_WAITING) {
- SIMIX_mbox_remove(comm->mbox, synchro);
- comm->state = SIMIX_CANCELED;
- }
- else if (!MC_is_active() /* when running the MC there are no surf actions */
- && !MC_record_replay_is_active()
- && (comm->state == SIMIX_READY || comm->state == SIMIX_RUNNING)) {
-
- comm->surf_comm->cancel();
- }
-}
-
-void SIMIX_comm_suspend(smx_synchro_t synchro)
-{
- synchro->suspend(); // FIXME: USELESS
-}
-
-void SIMIX_comm_resume(smx_synchro_t synchro)
-{
- synchro->resume(); // FIXME: USELESS
-}
-
-
-/************* synchro Getters **************/
-
-/**
- * \brief get the amount remaining from the communication
- * \param synchro The communication
- */
-double SIMIX_comm_get_remains(smx_synchro_t synchro)
-{
- if(!synchro)
- return 0;
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- double remains;
- switch (synchro->state) {
-
- case SIMIX_RUNNING:
- remains = comm->surf_comm->getRemains();
- break;
-
- case SIMIX_WAITING:
- case SIMIX_READY:
- remains = 0; /*FIXME: check what should be returned */
- break;
-
- default:
- remains = 0; /*FIXME: is this correct? */
- break;
- }
- return remains;
-}
-
-e_smx_state_t SIMIX_comm_get_state(smx_synchro_t synchro)
-{
- return synchro->state;
-}
-
-/**
- * \brief Return the user data associated to the sender of the communication
- * \param synchro The communication
- * \return the user data
- */
-void* SIMIX_comm_get_src_data(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- return comm->src_data;
-}
-
-/**
- * \brief Return the user data associated to the receiver of the communication
- * \param synchro The communication
- * \return the user data
- */
-void* SIMIX_comm_get_dst_data(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- return comm->dst_data;
-}
-
-smx_process_t SIMIX_comm_get_src_proc(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- return comm->src_proc;
-}
-
-smx_process_t SIMIX_comm_get_dst_proc(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- return comm->dst_proc;
-}
-
/******************************************************************************/
/* SIMIX_comm_copy_data callbacks */
/******************************************************************************/