Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'coverity_scan' of github.com:mquinson/simgrid
[simgrid.git] / src / s4u / s4u_host.cpp
index d68e07a..7aaf021 100644 (file)
@@ -46,27 +46,40 @@ Host::Host(const char* name)
 }
 
 Host::~Host() {
-       delete pimpl_cpu;
-       delete mounts;
+  delete pimpl_cpu;
+  delete mounts;
 }
 
 Host *Host::by_name(std::string name) {
-       Host* host = Host::by_name_or_null(name.c_str());
-       // TODO, raise an exception instead?
-       if (host == nullptr)
-               xbt_die("No such host: %s", name.c_str());
-       return host;
+  Host* host = Host::by_name_or_null(name.c_str());
+  // TODO, raise an exception instead?
+  if (host == nullptr)
+    xbt_die("No such host: %s", name.c_str());
+  return host;
+}
+Host* Host::by_name_or_null(const char* name)
+{
+  return (Host*) xbt_dict_get_or_null(host_list, name);
+}
+Host* Host::by_name_or_create(const char* name)
+{
+  Host* host = by_name_or_null(name);
+  if (host == nullptr) {
+    host = new Host(name);
+    xbt_dict_set(host_list, name, host, NULL);
+  }
+  return host;
 }
 
 Host *Host::current(){
-       smx_process_t smx_proc = SIMIX_process_self();
-       if (smx_proc == NULL)
-               xbt_die("Cannot call Host::current() from the maestro context");
-       return SIMIX_process_get_host(smx_proc);
+  smx_process_t smx_proc = SIMIX_process_self();
+  if (smx_proc == NULL)
+    xbt_die("Cannot call Host::current() from the maestro context");
+  return SIMIX_process_get_host(smx_proc);
 }
 
 void Host::turn_on() {
-       simgrid::simix::kernel(std::bind(SIMIX_host_on, this));
+  simgrid::simix::kernel(std::bind(SIMIX_host_on, this));
 }
 
 void Host::turn_off() {
@@ -74,37 +87,37 @@ void Host::turn_off() {
 }
 
 bool Host::is_on() {
-       return this->pimpl_cpu->isOn();
+  return this->pimpl_cpu->isOn();
 }
 
 int Host::pstates_count() const {
-       return this->pimpl_cpu->getNbPStates();
+  return this->pimpl_cpu->getNbPStates();
 }
 
 boost::unordered_map<std::string, Storage*> const& Host::mounted_storages() {
-       if (mounts == NULL) {
-               mounts = new boost::unordered_map<std::string, Storage*> ();
-
-               xbt_dict_t dict = this->mounted_storages_as_dict();
-
-               xbt_dict_cursor_t cursor;
-               char *mountname;
-               char *storagename;
-               xbt_dict_foreach(dict, cursor, mountname, storagename) {
-                       mounts->insert({mountname, &Storage::byName(storagename)});
-               }
-               xbt_dict_free(&dict);
-       }
+  if (mounts == NULL) {
+    mounts = new boost::unordered_map<std::string, Storage*> ();
+
+    xbt_dict_t dict = this->mounted_storages_as_dict();
+
+    xbt_dict_cursor_t cursor;
+    char *mountname;
+    char *storagename;
+    xbt_dict_foreach(dict, cursor, mountname, storagename) {
+      mounts->insert({mountname, &Storage::byName(storagename)});
+    }
+    xbt_dict_free(&dict);
+  }
 
-       return *mounts;
+  return *mounts;
 }
 
 /** Get the properties assigned to a host */
 xbt_dict_t Host::properties() {
   return simgrid::simix::kernel([&] {
-               simgrid::surf::Host* surf_host = this->extension<simgrid::surf::Host>();
-               return surf_host->getProperties();
-       });
+    simgrid::surf::Host* surf_host = this->extension<simgrid::surf::Host>();
+    return surf_host->getProperties();
+  });
 }
 
 /** Get the processes attached to the host */
@@ -133,26 +146,11 @@ double Host::power_peak_at(int pstate_index)
 
 /** @brief Get the speed of the cpu associated to a host */
 double Host::speed() {
-       return pimpl_cpu->getSpeed(1.0);
+  return pimpl_cpu->getSpeed(1.0);
 }
 /** @brief Returns the number of core of the processor. */
 int Host::core_count() {
-       return pimpl_cpu->getCore();
-}
-
-Host* Host::by_name_or_null(const char* name)
-{
-  return (Host*) xbt_dict_get_or_null(host_list, name);
-}
-
-Host* Host::by_name_or_create(const char* name)
-{
-  Host* host = by_name_or_null(name);
-  if (host == nullptr) {
-    host = new Host(name);
-    xbt_dict_set(host_list, name, host, NULL);
-  }
-  return host;
+  return pimpl_cpu->getCore();
 }
 
 /** @brief Set the pstate at which the host should run */