xbt_fifo_free(simcalls);
xbt_free(name);
}
+
+void simgrid::simix::Synchro::ref()
+{
+ refcount++;
+}
+void simgrid::simix::Synchro::unref()
+{
+ xbt_assert(refcount > 0,
+ "This synchro has a negative refcount! You can only call test() or wait() once per synchronization.");
+
+ refcount--;
+ if (refcount>0)
+ return;
+ delete this;
+}
virtual void suspend()=0;
virtual void resume()=0;
+
+ void ref();
+ void unref();
+ private:
+ int refcount=1;
};
}} // namespace simgrid::simix
#else /* not C++ */
simgrid::simix::Comm::Comm(e_smx_comm_type_t _type) {
state = SIMIX_WAITING;
this->type = _type;
- refcount = 1;
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? */
}
}
-void simgrid::simix::Comm::unref()
-{
- XBT_DEBUG("Destroy synchro %p (refcount: %d), state: %d", this, refcount, (int)state);
-
- xbt_assert(refcount > 0,
- "This comm has a negative refcount! You must not call test() or wait() more than once on a given communication.");
-
- refcount--;
- if (refcount > 0)
- return;
- XBT_DEBUG("Really free communication %p; refcount is now %d", this, refcount);
-
- 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);
-
- delete this;
-}
-
/** @brief This is part of the cleanup process, probably an internal command */
void simgrid::simix::Comm::cleanupSurf()
{
namespace simix {
XBT_PUBLIC_CLASS Comm : public Synchro {
+ ~Comm();
public:
Comm(e_smx_comm_type_t type);
void suspend();
void resume();
void cancel();
double remains();
- void unref();
void cleanupSurf(); // FIXME: make me protected
e_smx_comm_type_t type; /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
(comm.mbox set to NULL when the communication is removed from the mailbox
(used as garbage collector)) */
#endif
- int refcount = 1; /* Number of processes involved in the cond */
bool detached = false; /* If detached or not */
void (*clean_fun)(void*); /* Function to clean the detached src_buf if something goes wrong */
#include "src/simix/SynchroExec.hpp"
#include "src/surf/surf_interface.hpp"
+simgrid::simix::Exec::~Exec()
+{
+ if (surf_exec)
+ surf_exec->unref();
+}
void simgrid::simix::Exec::suspend()
{
if (surf_exec)
return 0;
}
-
-void simgrid::simix::Exec::unref()
-{
- refcount--;
- if (refcount > 0)
- return;
-
- if (surf_exec)
- surf_exec->unref();
-
- delete this;
-}
namespace simix {
XBT_PUBLIC_CLASS Exec : public Synchro {
+ ~Exec();
public:
void suspend();
void resume();
double remains();
- void unref();
sg_host_t host; /* The host where the execution takes place */
surf_action_t surf_exec; /* The Surf execution action encapsulated */
- private:
- int refcount = 1;
};
}} // namespace simgrid::simix
XBT_DEBUG("Found a matching communication synchro %p", comm);
if (remove_matching)
deque->erase(it);
- comm->refcount++;
+ comm->ref();
#if HAVE_MC
comm->mbox_cpy = comm->mbox;
#endif
//this mailbox is for small messages, which have to be sent right now
other_synchro->state = SIMIX_READY;
other_comm->dst_proc=mbox->permanent_receiver;
- other_comm->refcount++;
+ other_comm->ref();
mbox->done_comm_queue->push_back(other_synchro);
other_comm->mbox=mbox;
XBT_DEBUG("pushing a message into the permanent receive fifo %p, comm %p", mbox, &(other_comm));
/* if the communication synchro is detached then decrease the refcount
* by one, so it will be eliminated by the receiver's destroy call */
if (detached) {
- other_comm->detached = 1;
- other_comm->refcount--;
+ other_comm->detached = true;
+ other_comm->ref();
other_comm->clean_fun = clean_fun;
} else {
other_comm->clean_fun = NULL;
other_comm->type = SIMIX_COMM_DONE;
other_comm->mbox = NULL;
}
- other_comm->refcount--;
+ other_comm->unref();
static_cast<simgrid::simix::Comm*>(this_synchro)->unref();
}
} else {
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) {
- simgrid::simix::Comm *other_comm = static_cast<simgrid::simix::Comm*>(other_synchro);
- other_comm->refcount--;
- }
+ if(other_synchro)
+ other_synchro->unref();
this_comm->unref();
return other_synchro;
comm, (int)comm->state, comm->src_proc, comm->dst_proc);
comm->dst_proc = NULL;
- if (comm->detached && comm->refcount == 1 && comm->src_proc != NULL) {
+ if (comm->detached && /* FIXME: This code should be moved within comm->unref() anyway. comm->refcount == 1 &&*/ comm->src_proc != NULL) {
/* the comm will be freed right now, remove it from the sender */
xbt_fifo_remove(comm->src_proc->comms, comm);
}