From: Martin Quinson Date: Sun, 11 Dec 2016 20:29:50 +0000 (+0100) Subject: please sonar, and other small cleanups X-Git-Tag: v3_14~74 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/bf6c2bfc3494a13dfeb329e9dba5145d1e33fe91?ds=sidebyside please sonar, and other small cleanups - Init members during initialization - One operation per line at most - Don't let fields uninited after the constructor - Obey our naming schema (fields' name end with _) --- diff --git a/src/kernel/activity/SynchroExec.cpp b/src/kernel/activity/SynchroExec.cpp index 15d9a21a17..5954df6833 100644 --- a/src/kernel/activity/SynchroExec.cpp +++ b/src/kernel/activity/SynchroExec.cpp @@ -11,12 +11,12 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process); -simgrid::kernel::activity::Exec::Exec(const char*name, sg_host_t hostarg) +simgrid::kernel::activity::Exec::Exec(const char*name, sg_host_t host) : + host_(host) { if (name) this->name = name; this->state = SIMIX_RUNNING; - this->host = hostarg; } simgrid::kernel::activity::Exec::~Exec() @@ -50,7 +50,7 @@ double simgrid::kernel::activity::Exec::remains() void simgrid::kernel::activity::Exec::post() { - if (host && host->isOff()) {/* FIMXE: handle resource failure for parallel tasks too */ + if (host_ && host_->isOff()) {/* FIMXE: handle resource failure for parallel tasks too */ /* If the host running the synchro failed, notice it. This way, the asking * process can be killed if it runs on that host itself */ state = SIMIX_FAILED; diff --git a/src/kernel/activity/SynchroExec.hpp b/src/kernel/activity/SynchroExec.hpp index c0e315f956..9269975d17 100644 --- a/src/kernel/activity/SynchroExec.hpp +++ b/src/kernel/activity/SynchroExec.hpp @@ -22,7 +22,7 @@ namespace activity { void post() override; double remains(); - sg_host_t host = nullptr; /* The host where the execution takes place. If nullptr, then this is a parallel exec (and only surf knows the hosts) */ + sg_host_t host_ = nullptr; /* The host where the execution takes place. If nullptr, then this is a parallel exec (and only surf knows the hosts) */ surf_action_t surf_exec = nullptr; /* The Surf execution action encapsulated */ surf::Action* timeoutDetector = nullptr; }; diff --git a/src/kernel/routing/AsClusterTorus.cpp b/src/kernel/routing/AsClusterTorus.cpp index 017dbc087f..495f5bbc9f 100644 --- a/src/kernel/routing/AsClusterTorus.cpp +++ b/src/kernel/routing/AsClusterTorus.cpp @@ -62,7 +62,8 @@ namespace simgrid { link.latency = cluster->lat; link.policy = cluster->sharing_policy; sg_platf_new_link(&link); - Link *linkUp, *linkDown; + Link* linkUp; + Link* linkDown; if (link.policy == SURF_LINK_FULLDUPLEX) { char *tmp_link = bprintf("%s_UP", link_id); linkUp = Link::byName(tmp_link); diff --git a/src/s4u/s4u_file.cpp b/src/s4u/s4u_file.cpp index 7512efb3a7..e6fe865dc0 100644 --- a/src/s4u/s4u_file.cpp +++ b/src/s4u/s4u_file.cpp @@ -20,10 +20,10 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files"); namespace simgrid { namespace s4u { -File::File(const char*fullpath, void *userdata) { +File::File(const char* fullpath, void* userdata) : path_(fullpath) +{ // this cannot fail because we get a xbt_die if the mountpoint does not exist pimpl_ = simcall_file_open(fullpath, Host::current()); - path_ = fullpath; } File::~File() { diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 04c1ee4fbd..c6e33340c2 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -13,16 +13,13 @@ namespace simgrid { namespace s4u { boost::unordered_map *Storage::storages_ = new boost::unordered_map (); -Storage::Storage(std::string name, smx_storage_t inferior) { - name_ = name; - pimpl_ = inferior; - +Storage::Storage(std::string name, smx_storage_t inferior) : + name_(name), pimpl_(inferior) +{ storages_->insert({name, this}); } -Storage::~Storage() { - // TODO Auto-generated destructor stub -} +Storage::~Storage() = default; smx_storage_t Storage::inferior() { return pimpl_; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 97ee3c2cac..6e9afb51a2 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -252,7 +252,8 @@ double CpuTiTgmr::getPowerScale(double a) * \param value Percentage of CPU speed available (useful to fixed tracing) * \return Integration trace structure */ -CpuTiTgmr::CpuTiTgmr(tmgr_trace_t speedTrace, double value) +CpuTiTgmr::CpuTiTgmr(tmgr_trace_t speedTrace, double value) : + speedTrace_(speedTrace) { double total_time = 0.0; trace_ = 0; @@ -274,12 +275,11 @@ CpuTiTgmr::CpuTiTgmr(tmgr_trace_t speedTrace, double value) } type_ = TRACE_DYNAMIC; - speedTrace_ = speedTrace; /* count the total time of trace file */ - for (auto val: speedTrace->event_list) { + for (auto val : speedTrace->event_list) total_time += val.delta; - } + trace_ = new CpuTiTrace(speedTrace); lastTime_ = total_time; total_ = trace_->integrateSimple(0, total_time); @@ -669,9 +669,8 @@ void CpuTi::modified(bool modified){ CpuTiAction::CpuTiAction(CpuTiModel *model_, double cost, bool failed, CpuTi *cpu) : CpuAction(model_, cost, failed) + , cpu_(cpu) { - cpu_ = cpu; - indexHeap_ = -1; cpu_->modified(true); } diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index 4636311edb..90f93fe1af 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -97,7 +97,7 @@ public: double getRemains() override; CpuTi *cpu_; - int indexHeap_; + int indexHeap_ = -1; int suspended_ = 0; public: boost::intrusive::list_member_hook<> action_ti_hook; diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index f488f01e65..ebbd2cfa78 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -150,10 +150,12 @@ Action *HostL07Model::executeParallelTask(int host_nb, sg_host_t *host_list, return new L07Action(this, host_nb, host_list, flops_amount, bytes_amount, rate); } - L07Action::L07Action(Model *model, int host_nb, sg_host_t *host_list, double *flops_amount, double *bytes_amount, double rate) : CpuAction(model, 1, 0) + , computationAmount_(flops_amount) + , communicationAmount_(bytes_amount) + , rate_(rate) { int nb_link = 0; int nb_used_host = 0; /* Only the hosts with something to compute (>0 flops) are counted) */ @@ -191,10 +193,7 @@ L07Action::L07Action(Model *model, int host_nb, sg_host_t *host_list, nb_used_host++; XBT_DEBUG("Creating a parallel task (%p) with %d hosts and %d unique links.", this, host_nb, nb_link); - this->computationAmount_ = flops_amount; - this->communicationAmount_ = bytes_amount; this->latency_ = latency; - this->rate_ = rate; this->variable_ = lmm_variable_new(model->getMaxminSystem(), this, 1.0, (rate > 0 ? rate : -1.0), diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 22ff9809a1..bf31e1f361 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -265,7 +265,8 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) } //add a limiter link (shared link to account for maximal bandwidth of the node) - linkUp = linkDown = nullptr; + linkUp = nullptr; + linkDown = nullptr; if(cluster->limiter_link!=0){ char *tmp_link = bprintf("%s_limiter", link_id); XBT_DEBUG("", tmp_link, cluster->limiter_link);