From 960626aa0b2164f44aa72bde8a8ac73a618a2afa Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 8 May 2016 16:01:20 +0200 Subject: [PATCH 1/1] turn SIMIX_comm_new() into a proper constructor --- src/simix/Synchro.h | 2 +- src/simix/SynchroComm.cpp | 10 ++++++++++ src/simix/SynchroComm.hpp | 23 ++++++++++++----------- src/simix/smx_network.cpp | 28 ++++------------------------ src/surf/xml/simgrid_dtd.c | 8 ++++---- 5 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/simix/Synchro.h b/src/simix/Synchro.h index 9ed8f9f019..d119a8d251 100644 --- a/src/simix/Synchro.h +++ b/src/simix/Synchro.h @@ -19,7 +19,7 @@ namespace simix { Synchro(); virtual ~Synchro(); e_smx_state_t state; /* State of the synchro */ - char *name; /* synchro name if any */ + char *name = nullptr; /* synchro name if any */ xbt_fifo_t simcalls; /* List of simcalls waiting for this synchro */ char *category = nullptr; /* For instrumentation */ diff --git a/src/simix/SynchroComm.cpp b/src/simix/SynchroComm.cpp index 69eca5dca4..8d3b6e8081 100644 --- a/src/simix/SynchroComm.cpp +++ b/src/simix/SynchroComm.cpp @@ -9,7 +9,17 @@ #include "simgrid/modelchecker.h" #include "src/mc/mc_replay.h" +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_network); +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); +} void simgrid::simix::Comm::suspend() { /* FIXME: shall we suspend also the timeout synchro? */ if (surf_comm) diff --git a/src/simix/SynchroComm.hpp b/src/simix/SynchroComm.hpp index 68a21e88b9..2a2f6615d2 100644 --- a/src/simix/SynchroComm.hpp +++ b/src/simix/SynchroComm.hpp @@ -21,20 +21,21 @@ namespace simix { XBT_PUBLIC_CLASS Comm : public Synchro { public: + Comm(e_smx_comm_type_t type); void suspend(); void resume(); void cancel(); e_smx_comm_type_t type; /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */ - smx_mailbox_t mbox; /* Rendez-vous where the comm is queued */ + smx_mailbox_t mbox = nullptr; /* Rendez-vous where the comm is queued */ #if HAVE_MC smx_mailbox_t mbox_cpy; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR (comm.mbox set to NULL when the communication is removed from the mailbox (used as garbage collector)) */ #endif - int refcount; /* Number of processes involved in the cond */ - int detached; /* If detached or not */ + int refcount = 1; /* Number of processes involved in the cond */ + int detached = 0; /* If detached or not */ void (*clean_fun)(void*); /* Function to clean the detached src_buf if something goes wrong */ int (*match_fun)(void*,void*,smx_synchro_t); /* Filter function used by the other side. It is used when @@ -43,20 +44,20 @@ namespace simix { void (*copy_data_fun) (smx_synchro_t, void*, size_t); /* Surf action data */ - surf_action_t surf_comm; /* The Surf communication action encapsulated */ - surf_action_t src_timeout; /* Surf's actions to instrument the timeouts */ - surf_action_t dst_timeout; /* Surf's actions to instrument the timeouts */ - smx_process_t src_proc; - smx_process_t dst_proc; + surf_action_t surf_comm = nullptr; /* The Surf communication action encapsulated */ + surf_action_t src_timeout = nullptr; /* Surf's actions to instrument the timeouts */ + surf_action_t dst_timeout = nullptr; /* Surf's actions to instrument the timeouts */ + smx_process_t src_proc = nullptr; + smx_process_t dst_proc = nullptr; double rate; double task_size; /* Data to be transfered */ - void *src_buff; - void *dst_buff; + void *src_buff = nullptr; + void *dst_buff = nullptr; size_t src_buff_size; size_t *dst_buff_size; - unsigned copied:1; /* whether the data were already copied */ + unsigned copied = 0; /* whether the data were already copied */ void* src_data; /* User data associated to communication */ void* dst_data; diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 850480fb4f..82e37ad25d 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -20,7 +20,6 @@ static xbt_dict_t mailboxes = xbt_dict_new_homogeneous(SIMIX_mbox_free); 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 *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); @@ -172,25 +171,6 @@ static smx_synchro_t _find_matching_comm(std::deque *deque, e_smx /* 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 @@ -269,7 +249,7 @@ smx_synchro_t simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_process_t sr 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. @@ -364,7 +344,7 @@ smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox, void 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 @@ -449,10 +429,10 @@ smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int 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; diff --git a/src/surf/xml/simgrid_dtd.c b/src/surf/xml/simgrid_dtd.c index 9921f433d0..f3167441c1 100644 --- a/src/surf/xml/simgrid_dtd.c +++ b/src/surf/xml/simgrid_dtd.c @@ -5813,8 +5813,8 @@ YY_RULE_SETUP if (!AX_surfxml_ASroute_src) FAIL("Required attribute `src' not set for `ASroute' element."); LEAVE; STag_surfxml_ASroute(); surfxml_pcdata_ix = 0; ETag_surfxml_ASroute(); popbuffer(); /* attribute */ switch (YY_START) { - case S_surfxml_AS: case S_surfxml_AS_3: case S_surfxml_AS_5: case S_surfxml_AS_6: SET(S_surfxml_AS_6); break; - case S_surfxml_AS_1: case S_surfxml_AS_4: case S_surfxml_AS_7: case S_surfxml_AS_8: SET(S_surfxml_AS_8); break; + case S_surfxml_AS_1: case S_surfxml_AS_3: case S_surfxml_AS_5: case S_surfxml_AS_6: SET(S_surfxml_AS_6); break; + case S_surfxml_AS: case S_surfxml_AS_4: case S_surfxml_AS_7: case S_surfxml_AS_8: SET(S_surfxml_AS_8); break; } } YY_BREAK @@ -5838,8 +5838,8 @@ YY_RULE_SETUP ETag_surfxml_ASroute(); popbuffer(); /* attribute */ switch (YY_START) { - case S_surfxml_AS: case S_surfxml_AS_3: case S_surfxml_AS_5: case S_surfxml_AS_6: SET(S_surfxml_AS_6); break; - case S_surfxml_AS_1: case S_surfxml_AS_4: case S_surfxml_AS_7: case S_surfxml_AS_8: SET(S_surfxml_AS_8); break; + case S_surfxml_AS_1: case S_surfxml_AS_3: case S_surfxml_AS_5: case S_surfxml_AS_6: SET(S_surfxml_AS_6); break; + case S_surfxml_AS: case S_surfxml_AS_4: case S_surfxml_AS_7: case S_surfxml_AS_8: SET(S_surfxml_AS_8); break; } } YY_BREAK -- 2.20.1