Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Declare functions "const" in src/s4u/.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 2 Jul 2020 13:02:59 +0000 (15:02 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 2 Jul 2020 13:55:57 +0000 (15:55 +0200)
include/simgrid/s4u/Engine.hpp
include/simgrid/s4u/Host.hpp
include/simgrid/s4u/Mailbox.hpp
src/s4u/s4u_Engine.cpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Mailbox.cpp

index 7294e60..58e0e8f 100644 (file)
@@ -41,14 +41,14 @@ public:
   static void shutdown();
 
   /** Run the simulation after initialization */
-  void run();
+  void run() const;
 
   /** @brief Retrieve the simulation time (in seconds) */
   static double get_clock();
   /** @brief Retrieve the engine singleton */
   static s4u::Engine* get_instance();
 
-  void load_platform(const std::string& platf);
+  void load_platform(const std::string& platf) const;
 
   XBT_ATTRIB_DEPRECATED_v330("Please change the return code of your actors to void") void register_function(
       const std::string& name, int (*code)(int, char**));
@@ -103,44 +103,44 @@ protected:
 
 public:
   /** Returns the amount of hosts existing in the platform. */
-  size_t get_host_count();
+  size_t get_host_count() const;
   /** Returns a vector of all hosts found in the platform.
    *
    * The order is generally different from the creation/declaration order in the XML platform because we use a hash
    * table internally.
    */
-  std::vector<Host*> get_all_hosts();
-  std::vector<Host*> get_filtered_hosts(const std::function<bool(Host*)>& filter);
-  Host* host_by_name(const std::string& name);
-  Host* host_by_name_or_null(const std::string& name);
+  std::vector<Host*> get_all_hosts() const;
+  std::vector<Host*> get_filtered_hosts(const std::function<bool(Host*)>& filter) const;
+  Host* host_by_name(const std::string& name) const;
+  Host* host_by_name_or_null(const std::string& name) const;
 
-  size_t get_link_count();
-  std::vector<Link*> get_all_links();
-  std::vector<Link*> get_filtered_links(const std::function<bool(Link*)>& filter);
-  Link* link_by_name(const std::string& name);
-  Link* link_by_name_or_null(const std::string& name);
+  size_t get_link_count() const;
+  std::vector<Link*> get_all_links() const;
+  std::vector<Link*> get_filtered_links(const std::function<bool(Link*)>& filter) const;
+  Link* link_by_name(const std::string& name) const;
+  Link* link_by_name_or_null(const std::string& name) const;
 
-  size_t get_actor_count();
-  std::vector<ActorPtr> get_all_actors();
-  std::vector<ActorPtr> get_filtered_actors(const std::function<bool(ActorPtr)>& filter);
+  size_t get_actor_count() const;
+  std::vector<ActorPtr> get_all_actors() const;
+  std::vector<ActorPtr> get_filtered_actors(const std::function<bool(ActorPtr)>& filter) const;
 
 #ifndef DOXYGEN
-  size_t get_storage_count();
-  std::vector<Storage*> get_all_storages();
-  Storage* storage_by_name(const std::string& name);
-  Storage* storage_by_name_or_null(const std::string& name);
+  size_t get_storage_count() const;
+  std::vector<Storage*> get_all_storages() const;
+  Storage* storage_by_name(const std::string& name) const;
+  Storage* storage_by_name_or_null(const std::string& name) const;
 #endif
 
-  std::vector<kernel::routing::NetPoint*> get_all_netpoints();
-  kernel::routing::NetPoint* netpoint_by_name_or_null(const std::string& name);
+  std::vector<kernel::routing::NetPoint*> get_all_netpoints() const;
+  kernel::routing::NetPoint* netpoint_by_name_or_null(const std::string& name) const;
 
-  NetZone* get_netzone_root();
+  NetZone* get_netzone_root() const;
   void set_netzone_root(const NetZone* netzone);
 
-  NetZone* netzone_by_name_or_null(const std::string& name);
+  NetZone* netzone_by_name_or_null(const std::string& name) const;
 
   /** @brief Retrieves all netzones of the type indicated by the template argument */
-  template <class T> std::vector<T*> get_filtered_netzones()
+  template <class T> std::vector<T*> get_filtered_netzones() const
   {
     static_assert(std::is_base_of<kernel::routing::NetZoneImpl, T>::value,
                   "Filtering netzones is only possible for subclasses of kernel::routing::NetZoneImpl");
index 254caf7..1e7bd8a 100644 (file)
@@ -188,12 +188,12 @@ public:
    * It is not a problem if the actor is not located on the called host.
    * The actor will not be migrated in this case. Such remote execution are easy in simulation.
    */
-  void execute(double flops);
+  void execute(double flops) const;
   /** Start an asynchronous computation on that host (possibly remote) */
-  ExecPtr exec_async(double flops_amounts);
+  ExecPtr exec_async(double flops_amounts) const;
 
   /** Block the calling actor on an execution located on the called host (with explicit priority) */
-  void execute(double flops, double priority);
+  void execute(double flops, double priority) const;
 
 private:
   xbt::string name_{"noname"};
index f60c070..35a9db7 100644 (file)
@@ -40,19 +40,19 @@ public:
   static Mailbox* by_name(const std::string& name);
 
   /** Returns whether the mailbox contains queued communications */
-  bool empty();
+  bool empty() const;
 
   /** Check if there is a communication going on in a mailbox. */
-  bool listen();
+  bool listen() const;
 
   /** Look if there is a communication going on in a mailbox and return the PID of the sender actor */
-  aid_t listen_from();
+  aid_t listen_from() const;
 
   /** Check if there is a communication ready to be consumed from a mailbox. */
-  bool ready();
+  bool ready() const;
 
   /** Gets the first element in the queue (without dequeuing it), or nullptr if none is there */
-  kernel::activity::CommImplPtr front();
+  kernel::activity::CommImplPtr front() const;
 
   /** Declare that the specified actor is a permanent receiver on that mailbox
    *
@@ -75,7 +75,7 @@ public:
   void set_receiver(ActorPtr actor);
 
   /** Return the actor declared as permanent receiver, or nullptr if none **/
-  ActorPtr get_receiver();
+  ActorPtr get_receiver() const;
 
   /** Creates (but don't start) a data transmission to that mailbox */
   CommPtr put_init();
index c773d0e..c072730 100644 (file)
@@ -82,7 +82,7 @@ double Engine::get_clock()
  * See also: :ref:`platform`.
  * \endrst
  */
-void Engine::load_platform(const std::string& platf)
+void Engine::load_platform(const std::string& platf) const
 {
   double start = xbt_os_time();
   parse_platform_file(platf);
@@ -151,12 +151,12 @@ void Engine::load_deployment(const std::string& deploy)
 }
 
 /** Returns the amount of hosts in the platform */
-size_t Engine::get_host_count()
+size_t Engine::get_host_count() const
 {
   return pimpl->hosts_.size();
 }
 
-std::vector<Host*> Engine::get_all_hosts()
+std::vector<Host*> Engine::get_all_hosts() const
 {
   std::vector<Host*> res;
   for (auto const& kv : pimpl->hosts_)
@@ -164,7 +164,7 @@ std::vector<Host*> Engine::get_all_hosts()
   return res;
 }
 
-std::vector<Host*> Engine::get_filtered_hosts(const std::function<bool(Host*)>& filter)
+std::vector<Host*> Engine::get_filtered_hosts(const std::function<bool(Host*)>& filter) const
 {
   std::vector<Host*> hosts;
   for (auto const& kv : pimpl->hosts_) {
@@ -189,7 +189,7 @@ void Engine::host_unregister(const std::string& name)
  *
  *  @throw std::invalid_argument if the searched host does not exist.
  */
-Host* Engine::host_by_name(const std::string& name)
+Host* Engine::host_by_name(const std::string& name) const
 {
   if (pimpl->hosts_.find(name) == pimpl->hosts_.end())
     throw std::invalid_argument(std::string("Host not found: '") + name + std::string("'"));
@@ -197,7 +197,7 @@ Host* Engine::host_by_name(const std::string& name)
 }
 
 /** @brief Find a host from its name (or nullptr if that host does not exist) */
-Host* Engine::host_by_name_or_null(const std::string& name)
+Host* Engine::host_by_name_or_null(const std::string& name) const
 {
   auto host = pimpl->hosts_.find(name);
   return host == pimpl->hosts_.end() ? nullptr : host->second;
@@ -207,7 +207,7 @@ Host* Engine::host_by_name_or_null(const std::string& name)
  *
  *  @throw std::invalid_argument if the searched link does not exist.
  */
-Link* Engine::link_by_name(const std::string& name)
+Link* Engine::link_by_name(const std::string& name) const
 {
   if (pimpl->links_.find(name) == pimpl->links_.end())
     throw std::invalid_argument(std::string("Link not found: ") + name);
@@ -216,7 +216,7 @@ Link* Engine::link_by_name(const std::string& name)
 }
 
 /** @brief Find an link from its name (or nullptr if that link does not exist) */
-Link* Engine::link_by_name_or_null(const std::string& name)
+Link* Engine::link_by_name_or_null(const std::string& name) const
 {
   auto link = pimpl->links_.find(name);
   return link == pimpl->links_.end() ? nullptr : link->second->get_iface();
@@ -233,13 +233,13 @@ void Engine::link_unregister(const std::string& name)
 }
 
 /** @brief Returns the amount of storages in the platform */
-size_t Engine::get_storage_count()
+size_t Engine::get_storage_count() const
 {
   return pimpl->storages_.size();
 }
 
 /** @brief Returns the list of all storages found in the platform */
-std::vector<Storage*> Engine::get_all_storages()
+std::vector<Storage*> Engine::get_all_storages() const
 {
   std::vector<Storage*> res;
   for (auto const& kv : pimpl->storages_)
@@ -251,7 +251,7 @@ std::vector<Storage*> Engine::get_all_storages()
  *
  *  @throw std::invalid_argument if the searched storage does not exist.
  */
-Storage* Engine::storage_by_name(const std::string& name)
+Storage* Engine::storage_by_name(const std::string& name) const
 {
   if (pimpl->storages_.find(name) == pimpl->storages_.end())
     throw std::invalid_argument(std::string("Storage not found: ") + name);
@@ -260,7 +260,7 @@ Storage* Engine::storage_by_name(const std::string& name)
 }
 
 /** @brief Find a storage from its name (or nullptr if that storage does not exist) */
-Storage* Engine::storage_by_name_or_null(const std::string& name)
+Storage* Engine::storage_by_name_or_null(const std::string& name) const
 {
   auto storage = pimpl->storages_.find(name);
   return storage == pimpl->storages_.end() ? nullptr : storage->second->get_iface();
@@ -277,13 +277,13 @@ void Engine::storage_unregister(const std::string& name)
 }
 
 /** @brief Returns the amount of links in the platform */
-size_t Engine::get_link_count()
+size_t Engine::get_link_count() const
 {
   return pimpl->links_.size();
 }
 
 /** @brief Returns the list of all links found in the platform */
-std::vector<Link*> Engine::get_all_links()
+std::vector<Link*> Engine::get_all_links() const
 {
   std::vector<Link*> res;
   for (auto const& kv : pimpl->links_)
@@ -291,7 +291,7 @@ std::vector<Link*> Engine::get_all_links()
   return res;
 }
 
-std::vector<Link*> Engine::get_filtered_links(const std::function<bool(Link*)>& filter)
+std::vector<Link*> Engine::get_filtered_links(const std::function<bool(Link*)>& filter) const
 {
   std::vector<Link*> filtered_list;
   for (auto const& kv : pimpl->links_) {
@@ -302,12 +302,12 @@ std::vector<Link*> Engine::get_filtered_links(const std::function<bool(Link*)>&
   return filtered_list;
 }
 
-size_t Engine::get_actor_count()
+size_t Engine::get_actor_count() const
 {
   return simix_global->process_list.size();
 }
 
-std::vector<ActorPtr> Engine::get_all_actors()
+std::vector<ActorPtr> Engine::get_all_actors() const
 {
   std::vector<ActorPtr> actor_list;
   for (auto const& kv : simix_global->process_list) {
@@ -316,7 +316,7 @@ std::vector<ActorPtr> Engine::get_all_actors()
   return actor_list;
 }
 
-std::vector<ActorPtr> Engine::get_filtered_actors(const std::function<bool(ActorPtr)>& filter)
+std::vector<ActorPtr> Engine::get_filtered_actors(const std::function<bool(ActorPtr)>& filter) const
 {
   std::vector<ActorPtr> actor_list;
   for (auto const& kv : simix_global->process_list) {
@@ -326,7 +326,7 @@ std::vector<ActorPtr> Engine::get_filtered_actors(const std::function<bool(Actor
   return actor_list;
 }
 
-void Engine::run()
+void Engine::run() const
 {
   /* Clean IO before the run */
   fflush(stdout);
@@ -340,7 +340,7 @@ void Engine::run()
 }
 
 /** @brief Retrieve the root netzone, containing all others */
-s4u::NetZone* Engine::get_netzone_root()
+s4u::NetZone* Engine::get_netzone_root() const
 {
   return pimpl->netzone_root_->get_iface();
 }
@@ -366,19 +366,19 @@ static NetZone* netzone_by_name_recursive(NetZone* current, const std::string& n
 }
 
 /** @brief Retrieve the NetZone of the given name (or nullptr if not found) */
-NetZone* Engine::netzone_by_name_or_null(const std::string& name)
+NetZone* Engine::netzone_by_name_or_null(const std::string& name) const
 {
   return netzone_by_name_recursive(get_netzone_root(), name);
 }
 
 /** @brief Retrieve the netpoint of the given name (or nullptr if not found) */
-kernel::routing::NetPoint* Engine::netpoint_by_name_or_null(const std::string& name)
+kernel::routing::NetPoint* Engine::netpoint_by_name_or_null(const std::string& name) const
 {
   auto netp = pimpl->netpoints_.find(name);
   return netp == pimpl->netpoints_.end() ? nullptr : netp->second;
 }
 
-std::vector<kernel::routing::NetPoint*> Engine::get_all_netpoints()
+std::vector<kernel::routing::NetPoint*> Engine::get_all_netpoints() const
 {
   std::vector<kernel::routing::NetPoint*> res;
   for (auto const& kv : pimpl->netpoints_)
index e5edd61..81f6158 100644 (file)
@@ -294,17 +294,17 @@ std::unordered_map<std::string, Storage*> const& Host::get_mounted_storages()
   return *mounts_;
 }
 
-ExecPtr Host::exec_async(double flops)
+ExecPtr Host::exec_async(double flops) const
 {
   return this_actor::exec_init(flops);
 }
 
-void Host::execute(double flops)
+void Host::execute(double flops) const
 {
   execute(flops, 1.0 /* priority */);
 }
 
-void Host::execute(double flops, double priority)
+void Host::execute(double flops, double priority) const
 {
   this_actor::exec_init(flops)->set_priority(1 / priority)->start()->wait();
 }
index abbf92e..72facec 100644 (file)
@@ -34,17 +34,17 @@ Mailbox* Mailbox::by_name(const std::string& name)
   return &mbox->piface_;
 }
 
-bool Mailbox::empty()
+bool Mailbox::empty() const
 {
   return pimpl_->comm_queue_.empty();
 }
 
-bool Mailbox::listen()
+bool Mailbox::listen() const
 {
   return not this->empty() || (pimpl_->permanent_receiver_ && not pimpl_->done_comm_queue_.empty());
 }
 
-aid_t Mailbox::listen_from()
+aid_t Mailbox::listen_from() const
 {
   kernel::activity::CommImplPtr comm = front();
   if (comm && comm->src_actor_)
@@ -53,7 +53,7 @@ aid_t Mailbox::listen_from()
     return -1;
 }
 
-bool Mailbox::ready()
+bool Mailbox::ready() const
 {
   bool comm_ready = false;
   if (not pimpl_->comm_queue_.empty()) {
@@ -65,7 +65,7 @@ bool Mailbox::ready()
   return comm_ready;
 }
 
-kernel::activity::CommImplPtr Mailbox::front()
+kernel::activity::CommImplPtr Mailbox::front() const
 {
   return pimpl_->comm_queue_.empty() ? nullptr : pimpl_->comm_queue_.front();
 }
@@ -76,7 +76,7 @@ void Mailbox::set_receiver(ActorPtr actor)
 }
 
 /** @brief get the receiver (process associated to the mailbox) */
-ActorPtr Mailbox::get_receiver()
+ActorPtr Mailbox::get_receiver() const
 {
   if (pimpl_->permanent_receiver_ == nullptr)
     return ActorPtr();