From: Martin Quinson Date: Thu, 19 Apr 2018 19:43:38 +0000 (+0200) Subject: start enforcing our new coding standards X-Git-Tag: v3.20~339 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/aee6610d4ad2377964369760bce27e18a12dd708 start enforcing our new coding standards --- diff --git a/src/s4u/s4u_activity.cpp b/src/s4u/s4u_Activity.cpp similarity index 86% rename from src/s4u/s4u_activity.cpp rename to src/s4u/s4u_Activity.cpp index 01a6aad8ab..d3eaaefd23 100644 --- a/src/s4u/s4u_activity.cpp +++ b/src/s4u/s4u_Activity.cpp @@ -10,7 +10,7 @@ #include "simgrid/s4u/Activity.hpp" XBT_LOG_EXTERNAL_CATEGORY(s4u); -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity,s4u,"S4U activities"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity, s4u, "S4U activities"); namespace simgrid { namespace s4u { @@ -27,5 +27,5 @@ Activity* Activity::set_remaining(double remains) return this; } -} -} +} // namespace s4u +} // namespace simgrid diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_Actor.cpp similarity index 97% rename from src/s4u/s4u_actor.cpp rename to src/s4u/s4u_Actor.cpp index 9afb7946d7..c4ac6914e5 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -36,7 +36,7 @@ ActorPtr Actor::create(const char* name, s4u::Host* host, std::function ActorPtr Actor::create(const char* name, s4u::Host* host, const char* function, std::vector args) { simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(function); - simgrid::simix::ActorCode code = factory(std::move(args)); + simgrid::simix::ActorCode code = factory(std::move(args)); simgrid::kernel::actor::ActorImpl* actor = simcall_process_create(name, std::move(code), nullptr, host, nullptr); return actor->iface(); } @@ -52,7 +52,8 @@ void intrusive_ptr_release(Actor* actor) // ***** Actor methods ***** -void Actor::join() { +void Actor::join() +{ simcall_process_join(this->pimpl_, -1); } @@ -177,7 +178,7 @@ int Actor::is_suspended() void Actor::set_kill_time(double time) { - simcall_process_set_kill_time(pimpl_,time); + simcall_process_set_kill_time(pimpl_, time); } /** \brief Get the kill time of an actor(or 0 if unset). */ @@ -190,7 +191,7 @@ void Actor::kill(aid_t pid) { smx_actor_t killer = SIMIX_process_self(); smx_actor_t process = SIMIX_process_from_PID(pid); - if(process != nullptr) { + if (process != nullptr) { simgrid::simix::kernelImmediate([killer, process] { SIMIX_process_kill(process, killer); }); } else { std::ostringstream oss; @@ -199,7 +200,8 @@ void Actor::kill(aid_t pid) } } -void Actor::kill() { +void Actor::kill() +{ smx_actor_t process = SIMIX_process_self(); simgrid::simix::kernelImmediate( [this, process] { SIMIX_process_kill(pimpl_, (pimpl_ == simix_global->maestro_process) ? pimpl_ : process); }); @@ -491,7 +493,7 @@ const char* sg_actor_get_property_value(sg_actor_t actor, const char* name) xbt_dict_t sg_actor_get_properties(sg_actor_t actor) { xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr"); - xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); + xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); std::map* props = actor->get_properties(); if (props == nullptr) return nullptr; @@ -561,11 +563,11 @@ void sg_actor_migrate(sg_actor_t process, sg_host_t host) } /** \ingroup m_actor_management -* \brief Wait for the completion of a #sg_actor_t. -* -* \param actor the actor to wait for -* \param timeout wait until the actor is over, or the timeout expires -*/ + * \brief Wait for the completion of a #sg_actor_t. + * + * \param actor the actor to wait for + * \param timeout wait until the actor is over, or the timeout expires + */ void sg_actor_join(sg_actor_t actor, double timeout) { actor->join(timeout); diff --git a/src/s4u/s4u_comm.cpp b/src/s4u/s4u_Comm.cpp similarity index 97% rename from src/s4u/s4u_comm.cpp rename to src/s4u/s4u_Comm.cpp index cbbb9c4597..cbcdf33117 100644 --- a/src/s4u/s4u_comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -9,7 +9,7 @@ #include "simgrid/s4u/Comm.hpp" #include "simgrid/s4u/Mailbox.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_comm,s4u_activity,"S4U asynchronous communications"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_comm, s4u_activity, "S4U asynchronous communications"); namespace simgrid { namespace s4u { @@ -200,7 +200,7 @@ bool Comm::test() if (state_ == State::inited) this->start(); - if(simcall_comm_test(pimpl_)){ + if (simcall_comm_test(pimpl_)) { state_ = State::finished; return true; } @@ -223,5 +223,5 @@ void intrusive_ptr_add_ref(simgrid::s4u::Comm* c) { c->refcount_.fetch_add(1, std::memory_order_relaxed); } -} -} // namespaces +} // namespace s4u +} // namespace simgrid diff --git a/src/s4u/s4u_conditionVariable.cpp b/src/s4u/s4u_ConditionVariable.cpp similarity index 88% rename from src/s4u/s4u_conditionVariable.cpp rename to src/s4u/s4u_ConditionVariable.cpp index 2881d9bf44..61d8c9c02c 100644 --- a/src/s4u/s4u_conditionVariable.cpp +++ b/src/s4u/s4u_ConditionVariable.cpp @@ -30,11 +30,13 @@ void ConditionVariable::wait(MutexPtr lock) simcall_cond_wait(cond_, lock->mutex_); } -void ConditionVariable::wait(std::unique_lock& lock) { +void ConditionVariable::wait(std::unique_lock& lock) +{ simcall_cond_wait(cond_, lock.mutex()->mutex_); } -std::cv_status s4u::ConditionVariable::wait_for(std::unique_lock& lock, double timeout) { +std::cv_status s4u::ConditionVariable::wait_for(std::unique_lock& lock, double timeout) +{ // The simcall uses -1 for "any timeout" but we don't want this: if (timeout < 0) timeout = 0.0; @@ -42,24 +44,21 @@ std::cv_status s4u::ConditionVariable::wait_for(std::unique_lock& lock, d try { simcall_cond_wait_timeout(cond_, lock.mutex()->mutex_, timeout); return std::cv_status::no_timeout; - } - catch (xbt_ex& e) { + } catch (xbt_ex& e) { // If the exception was a timeout, we have to take the lock again: if (e.category == timeout_error) { try { lock.mutex()->lock(); return std::cv_status::timeout; - } - catch (...) { + } catch (...) { std::terminate(); } } // Another exception: should we reaquire the lock? std::terminate(); - } - catch (...) { + } catch (...) { std::terminate(); } } @@ -78,11 +77,13 @@ std::cv_status ConditionVariable::wait_until(std::unique_lock& lock, doub /** * Notify functions */ -void ConditionVariable::notify_one() { +void ConditionVariable::notify_one() +{ simgrid::simix::kernelImmediate([this]() { cond_->signal(); }); } -void ConditionVariable::notify_all() { +void ConditionVariable::notify_all() +{ simgrid::simix::kernelImmediate([this]() { cond_->broadcast(); }); } @@ -96,5 +97,5 @@ void intrusive_ptr_release(ConditionVariable* cond) intrusive_ptr_release(cond->cond_); } -} -} +} // namespace s4u +} // namespace simgrid diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_Engine.cpp similarity index 84% rename from src/s4u/s4u_engine.cpp rename to src/s4u/s4u_Engine.cpp index 0510bbb5a1..5374db3345 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -19,7 +19,7 @@ #include "src/surf/network_interface.hpp" #include "surf/surf.hpp" // routing_platf. FIXME:KILLME. SOON -XBT_LOG_NEW_CATEGORY(s4u,"Log channels of the S4U (Simgrid for you) interface"); +XBT_LOG_NEW_CATEGORY(s4u, "Log channels of the S4U (Simgrid for you) interface"); namespace simgrid { namespace s4u { @@ -28,10 +28,12 @@ xbt::signal onSimulationEnd; xbt::signal onTimeAdvance; xbt::signal onDeadlock; -Engine *Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */ +Engine* Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */ -Engine::Engine(int *argc, char **argv) { - xbt_assert(s4u::Engine::instance_ == nullptr, "It is currently forbidden to create more than one instance of s4u::Engine"); +Engine::Engine(int* argc, char** argv) +{ + xbt_assert(s4u::Engine::instance_ == nullptr, + "It is currently forbidden to create more than one instance of s4u::Engine"); TRACE_global_init(); SIMIX_global_init(argc, argv); @@ -53,7 +55,8 @@ Engine* Engine::getInstance() return s4u::Engine::instance_; } -void Engine::shutdown() { +void Engine::shutdown() +{ delete s4u::Engine::instance_; s4u::Engine::instance_ = nullptr; } @@ -63,20 +66,20 @@ double Engine::getClock() return SIMIX_get_clock(); } -void Engine::loadPlatform(const char *platf) +void Engine::loadPlatform(const char* platf) { SIMIX_create_environment(platf); } -void Engine::registerFunction(const char*name, int (*code)(int,char**)) +void Engine::registerFunction(const char* name, int (*code)(int, char**)) { - SIMIX_function_register(name,code); + SIMIX_function_register(name, code); } -void Engine::registerDefault(int (*code)(int,char**)) +void Engine::registerDefault(int (*code)(int, char**)) { SIMIX_function_register_default(code); } -void Engine::loadDeployment(const char *deploy) +void Engine::loadDeployment(const char* deploy) { SIMIX_launch_application(deploy); } @@ -88,8 +91,9 @@ size_t Engine::getHostCount() /** @brief Fills the passed list with all hosts found in the platform * @deprecated Please prefer Engine::getAllHosts() */ -void XBT_ATTRIB_DEPRECATED_v322("Engine::getHostList() is deprecated in favor of Engine::getAllHosts(). Please switch before v3.22") -Engine::getHostList(std::vector* list) +void XBT_ATTRIB_DEPRECATED_v322( + "Engine::getHostList() is deprecated in favor of Engine::getAllHosts(). Please switch before v3.22") + Engine::getHostList(std::vector* list) { for (auto const& kv : pimpl->hosts_) list->push_back(kv.second); @@ -164,8 +168,9 @@ size_t Engine::getLinkCount() /** @brief Fills the passed list with all links found in the platform * * @deprecated. Prefer Engine::getAllLinks() */ -void XBT_ATTRIB_DEPRECATED_v322("Engine::getLinkList() is deprecated in favor of Engine::getAllLinks(). Please switch before v3.22") -Engine::getLinkList(std::vector* list) +void XBT_ATTRIB_DEPRECATED_v322( + "Engine::getLinkList() is deprecated in favor of Engine::getAllLinks(). Please switch before v3.22") + Engine::getLinkList(std::vector* list) { kernel::resource::LinkImpl::linksList(list); } @@ -178,7 +183,8 @@ std::vector Engine::getAllLinks() return res; } -void Engine::run() { +void Engine::run() +{ if (MC_is_active()) { MC_run(); } else { @@ -248,5 +254,5 @@ void Engine::setConfig(std::string str) { simgrid::config::set_parse(std::move(str)); } -} -} // namespace +} // namespace s4u +} // namespace simgrid diff --git a/src/s4u/s4u_exec.cpp b/src/s4u/s4u_Exec.cpp similarity index 98% rename from src/s4u/s4u_exec.cpp rename to src/s4u/s4u_Exec.cpp index 0e2d39b2ef..03afd33a5c 100644 --- a/src/s4u/s4u_exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -99,5 +99,5 @@ void intrusive_ptr_add_ref(simgrid::s4u::Exec* e) { e->refcount_.fetch_add(1, std::memory_order_relaxed); } -} -} +} // namespace s4u +} // namespace simgrid diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_Host.cpp similarity index 95% rename from src/s4u/s4u_host.cpp rename to src/s4u/s4u_Host.cpp index 78e9b73f01..f65d3f0986 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -27,8 +27,7 @@ simgrid::xbt::signal Host::onDestruction; simgrid::xbt::signal Host::onStateChange; simgrid::xbt::signal Host::onSpeedChange; -Host::Host(const char* name) - : name_(name) +Host::Host(const char* name) : name_(name) { xbt_assert(Host::by_name_or_null(name) == nullptr, "Refusing to create a second host named '%s'.", name); Engine::getInstance()->addHost(std::string(name_), this); @@ -81,14 +80,16 @@ Host* Host::by_name_or_null(std::string name) return Engine::getInstance()->hostByNameOrNull(name); } -Host *Host::current(){ +Host* Host::current() +{ smx_actor_t smx_proc = SIMIX_process_self(); if (smx_proc == nullptr) xbt_die("Cannot call Host::current() from the maestro context"); return smx_proc->host; } -void Host::turnOn() { +void Host::turnOn() +{ if (isOff()) { simgrid::simix::kernelImmediate([this] { this->extension()->turnOn(); @@ -98,7 +99,8 @@ void Host::turnOn() { } } -void Host::turnOff() { +void Host::turnOff() +{ if (isOn()) { smx_actor_t self = SIMIX_process_self(); simgrid::simix::kernelImmediate([this, self] { @@ -108,7 +110,8 @@ void Host::turnOff() { } } -bool Host::isOn() { +bool Host::isOn() +{ return this->pimpl_cpu->is_on(); } @@ -196,9 +199,8 @@ int Host::get_actor_count() /** @brief Get the peak processor speed (in flops/s), at the specified pstate */ double Host::getPstateSpeed(int pstate_index) { - return simgrid::simix::kernelImmediate([this, pstate_index] { - return this->pimpl_cpu->getPstateSpeed(pstate_index); - }); + return simgrid::simix::kernelImmediate( + [this, pstate_index] { return this->pimpl_cpu->getPstateSpeed(pstate_index); }); } /** @brief Get the peak processor speed (under full load (=1.0), in flops/s), at the current pstate */ @@ -216,9 +218,7 @@ int Host::getCoreCount() /** @brief Set the pstate at which the host should run */ void Host::setPstate(int pstate_index) { - simgrid::simix::kernelImmediate([this, pstate_index] { - this->pimpl_cpu->setPState(pstate_index); - }); + simgrid::simix::kernelImmediate([this, pstate_index] { this->pimpl_cpu->setPState(pstate_index); }); } /** @brief Retrieve the pstate at which the host is currently running */ int Host::getPstate() @@ -269,5 +269,5 @@ double Host::getLoad() return this->pimpl_cpu->get_load(); } -} // namespace simgrid } // namespace s4u +} // namespace simgrid diff --git a/src/s4u/s4u_link.cpp b/src/s4u/s4u_Link.cpp similarity index 87% rename from src/s4u/s4u_link.cpp rename to src/s4u/s4u_Link.cpp index 46a75c6256..512c2a7793 100644 --- a/src/s4u/s4u_link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -54,7 +54,7 @@ int sg_link_count() sg_link_t* sg_link_list() { simgrid::kernel::resource::LinkImpl** list = simgrid::kernel::resource::LinkImpl::linksList(); - sg_link_t* res = (sg_link_t*)list; // Use the same memory area + sg_link_t* res = (sg_link_t*)list; // Use the same memory area int size = sg_link_count(); for (int i = 0; i < size; i++) @@ -132,28 +132,20 @@ void* Link::getData() } void Link::setData(void* d) { - simgrid::simix::kernelImmediate([this, d]() { - this->pimpl_->setData(d); - }); + simgrid::simix::kernelImmediate([this, d]() { this->pimpl_->setData(d); }); } void Link::setStateTrace(tmgr_trace_t trace) { - simgrid::simix::kernelImmediate([this, trace]() { - this->pimpl_->setStateTrace(trace); - }); + simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setStateTrace(trace); }); } void Link::setBandwidthTrace(tmgr_trace_t trace) { - simgrid::simix::kernelImmediate([this, trace]() { - this->pimpl_->setBandwidthTrace(trace); - }); + simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setBandwidthTrace(trace); }); } void Link::setLatencyTrace(tmgr_trace_t trace) { - simgrid::simix::kernelImmediate([this, trace]() { - this->pimpl_->setLatencyTrace(trace); - }); + simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setLatencyTrace(trace); }); } const char* Link::getProperty(const char* key) @@ -173,5 +165,5 @@ simgrid::xbt::signal Link::onDestruction; simgrid::xbt::signal Link::onStateChange; simgrid::xbt::signal Link::onCommunicate; simgrid::xbt::signal Link::onCommunicationStateChange; -} -} +} // namespace s4u +} // namespace simgrid diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_Mailbox.cpp similarity index 91% rename from src/s4u/s4u_mailbox.cpp rename to src/s4u/s4u_Mailbox.cpp index 8d981638af..c135ce70c3 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_Mailbox.cpp @@ -11,7 +11,7 @@ #include "xbt/log.h" XBT_LOG_EXTERNAL_CATEGORY(s4u); -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel,s4u,"S4U Communication Mailboxes"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel, s4u, "S4U Communication Mailboxes"); namespace simgrid { namespace s4u { @@ -26,13 +26,11 @@ const char* Mailbox::get_cname() const return pimpl_->get_cname(); } -MailboxPtr Mailbox::byName(const char*name) +MailboxPtr Mailbox::byName(const char* name) { kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::byNameOrNull(name); if (mbox == nullptr) { - mbox = simix::kernelImmediate([name] { - return kernel::activity::MailboxImpl::byNameOrCreate(name); - }); + mbox = simix::kernelImmediate([name] { return kernel::activity::MailboxImpl::byNameOrCreate(name); }); } return MailboxPtr(&mbox->piface_, true); } @@ -57,7 +55,8 @@ smx_activity_t Mailbox::front() return pimpl_->comm_queue.empty() ? nullptr : pimpl_->comm_queue.front(); } -void Mailbox::setReceiver(ActorPtr actor) { +void Mailbox::setReceiver(ActorPtr actor) +{ simix::kernelImmediate([this, actor]() { this->pimpl_->setReceiver(actor); }); } @@ -144,5 +143,5 @@ void* Mailbox::get(double timeout) c->wait(timeout); return res; } -} -} +} // namespace s4u +} // namespace simgrid diff --git a/src/s4u/s4u_mutex.cpp b/src/s4u/s4u_Mutex.cpp similarity index 96% rename from src/s4u/s4u_mutex.cpp rename to src/s4u/s4u_Mutex.cpp index 09d36548e0..6c5d171902 100644 --- a/src/s4u/s4u_mutex.cpp +++ b/src/s4u/s4u_Mutex.cpp @@ -51,5 +51,5 @@ void intrusive_ptr_release(Mutex* mutex) xbt_assert(mutex); SIMIX_mutex_unref(mutex->mutex_); } -} -} +} // namespace s4u +} // namespace simgrid diff --git a/src/s4u/s4u_netzone.cpp b/src/s4u/s4u_Netzone.cpp similarity index 95% rename from src/s4u/s4u_netzone.cpp rename to src/s4u/s4u_Netzone.cpp index 5588961b53..e62b0afcde 100644 --- a/src/s4u/s4u_netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -40,9 +40,7 @@ NetZone::~NetZone() std::unordered_map* NetZone::getProperties() { - return simgrid::simix::kernelImmediate([this] { - return &properties_; - }); + return simgrid::simix::kernelImmediate([this] { return &properties_; }); } /** Retrieve the property value (or nullptr if not set) */ @@ -52,9 +50,7 @@ const char* NetZone::getProperty(const char* key) } void NetZone::setProperty(const char* key, const char* value) { - simgrid::simix::kernelImmediate([this,key,value] { - properties_[key] = value; - }); + simgrid::simix::kernelImmediate([this, key, value] { properties_[key] = value; }); } /** @brief Returns the list of direct children (no grand-children) diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_Storage.cpp similarity index 96% rename from src/s4u/s4u_storage.cpp rename to src/s4u/s4u_Storage.cpp index 780d5c71a2..4179d0cf87 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_Storage.cpp @@ -123,7 +123,7 @@ const char* sg_storage_get_host(sg_storage_t storage) xbt_dict_t sg_storage_get_properties(sg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)"); - xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); + xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); std::map* props = storage->getProperties(); if (props == nullptr) return nullptr; @@ -173,7 +173,7 @@ sg_storage_t sg_storage_get_by_name(const char* name) xbt_dynar_t sg_storages_as_dynar() { std::vector storage_list = simgrid::s4u::Engine::getInstance()->getAllStorages(); - xbt_dynar_t res = xbt_dynar_new(sizeof(sg_storage_t), nullptr); + xbt_dynar_t res = xbt_dynar_new(sizeof(sg_storage_t), nullptr); for (auto const& s : storage_list) xbt_dynar_push(res, &s); return res; diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index deb8d7e989..6913ae3bb3 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -422,18 +422,18 @@ else() endif() set(S4U_SRC - src/s4u/s4u_actor.cpp - src/s4u/s4u_activity.cpp - src/s4u/s4u_conditionVariable.cpp - src/s4u/s4u_comm.cpp - src/s4u/s4u_engine.cpp - src/s4u/s4u_exec.cpp - src/s4u/s4u_host.cpp - src/s4u/s4u_link.cpp - src/s4u/s4u_mailbox.cpp - src/s4u/s4u_mutex.cpp - src/s4u/s4u_netzone.cpp - src/s4u/s4u_storage.cpp + src/s4u/s4u_Actor.cpp + src/s4u/s4u_Activity.cpp + src/s4u/s4u_ConditionVariable.cpp + src/s4u/s4u_Comm.cpp + src/s4u/s4u_Engine.cpp + src/s4u/s4u_Exec.cpp + src/s4u/s4u_Host.cpp + src/s4u/s4u_Link.cpp + src/s4u/s4u_Mailbox.cpp + src/s4u/s4u_Mutex.cpp + src/s4u/s4u_Netzone.cpp + src/s4u/s4u_Storage.cpp ) set(SIMGRID_SRC