X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e49a7949060118737703106058657735cf3892d6..b08cf565e62c980d3fa23c031b341ca4f1427bd9:/src/simix/SynchroComm.cpp diff --git a/src/simix/SynchroComm.cpp b/src/simix/SynchroComm.cpp index 69eca5dca4..4342cb107e 100644 --- a/src/simix/SynchroComm.cpp +++ b/src/simix/SynchroComm.cpp @@ -9,8 +9,37 @@ #include "simgrid/modelchecker.h" #include "src/mc/mc_replay.h" +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_network); -void simgrid::simix::Comm::suspend() { +simgrid::simix::Comm::Comm(e_smx_comm_type_t _type) { + state = SIMIX_WAITING; + this->type = _type; + src_data=NULL; + dst_data=NULL; + + XBT_DEBUG("Create communicate synchro %p", this); +} + +simgrid::simix::Comm::~Comm() +{ + XBT_DEBUG("Really free communication %p", this); + + cleanupSurf(); + + if (detached && state != SIMIX_DONE) { + /* the communication has failed and was detached: + * we have to free the buffer */ + if (clean_fun) + clean_fun(src_buff); + src_buff = NULL; + } + + if(mbox) + SIMIX_mbox_remove(mbox, this); + +} +void simgrid::simix::Comm::suspend() +{ /* FIXME: shall we suspend also the timeout synchro? */ if (surf_comm) surf_comm->suspend(); @@ -18,14 +47,16 @@ void simgrid::simix::Comm::suspend() { } -void simgrid::simix::Comm::resume() { +void simgrid::simix::Comm::resume() +{ /*FIXME: check what happen with the timeouts */ if (surf_comm) surf_comm->resume(); /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */ } -void simgrid::simix::Comm::cancel() { +void simgrid::simix::Comm::cancel() +{ /* if the synchro is a waiting state means that it is still in a mbox */ /* so remove from it and delete it */ if (state == SIMIX_WAITING) { @@ -39,3 +70,69 @@ void simgrid::simix::Comm::cancel() { surf_comm->cancel(); } } + +/** @brief get the amount remaining from the communication */ +double simgrid::simix::Comm::remains() +{ + switch (state) { + + case SIMIX_RUNNING: + return surf_comm->getRemains(); + break; + + case SIMIX_WAITING: + case SIMIX_READY: + return 0; /*FIXME: check what should be returned */ + break; + + default: + return 0; /*FIXME: is this correct? */ + break; + } +} + +/** @brief This is part of the cleanup process, probably an internal command */ +void simgrid::simix::Comm::cleanupSurf() +{ + if (surf_comm){ + surf_comm->unref(); + surf_comm = NULL; + } + + if (src_timeout){ + src_timeout->unref(); + src_timeout = NULL; + } + + if (dst_timeout){ + dst_timeout->unref(); + dst_timeout = NULL; + } +} + +void simgrid::simix::Comm::post() +{ + /* Update synchro state */ + if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::done) + state = SIMIX_SRC_TIMEOUT; + else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::done) + state = SIMIX_DST_TIMEOUT; + else if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::failed) + state = SIMIX_SRC_HOST_FAILURE; + else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::failed) + state = SIMIX_DST_HOST_FAILURE; + else if (surf_comm && surf_comm->getState() == simgrid::surf::Action::State::failed) { + state = SIMIX_LINK_FAILURE; + } else + state = SIMIX_DONE; + + XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d", + this, (int)state, src_proc, dst_proc, detached); + + /* destroy the surf actions associated with the Simix communication */ + cleanupSurf(); + + /* if there are simcalls associated with the synchro, then answer them */ + if (xbt_fifo_size(simcalls)) + SIMIX_comm_finish(this); +}