Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Constify get_properties() and and remove simcalls.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 17 Apr 2019 21:21:48 +0000 (23:21 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 18 Apr 2019 09:46:58 +0000 (11:46 +0200)
20 files changed:
examples/s4u/platform-properties/s4u-platform-properties.cpp
include/simgrid/kernel/routing/NetZoneImpl.hpp
include/simgrid/s4u/Actor.hpp
include/simgrid/s4u/Host.hpp
include/simgrid/s4u/Link.hpp
include/simgrid/s4u/NetZone.hpp
include/simgrid/s4u/Storage.hpp
src/kernel/actor/ActorImpl.cpp
src/kernel/actor/ActorImpl.hpp
src/kernel/routing/NetZoneImpl.cpp
src/s4u/s4u_Actor.cpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Link.cpp
src/s4u/s4u_Netzone.cpp
src/s4u/s4u_Storage.cpp
src/surf/PropertyHolder.cpp
src/surf/PropertyHolder.hpp
teshsuite/s4u/storage_client_server/storage_client_server.cpp
teshsuite/s4u/storage_client_server/storage_client_server.tesh
teshsuite/simdag/flatifier/flatifier.cpp

index fe49596..e85410a 100644 (file)
@@ -14,7 +14,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Property test");
 static void test_host(const std::string& hostname)
 {
   simgrid::s4u::Host* thehost = simgrid::s4u::Host::by_name(hostname);
 static void test_host(const std::string& hostname)
 {
   simgrid::s4u::Host* thehost = simgrid::s4u::Host::by_name(hostname);
-  std::unordered_map<std::string, std::string>* props = thehost->get_properties();
+  const std::unordered_map<std::string, std::string>* props = thehost->get_properties();
   const char* noexist = "Unknown";
   const char* exist   = "Hdd";
   const char* value;
   const char* noexist = "Unknown";
   const char* exist   = "Hdd";
   const char* value;
@@ -81,7 +81,7 @@ static void bob(std::vector<std::string> /*args*/)
   XBT_INFO("   Zone property: author -> %s", root->get_property("author"));
 
   /* Get the property list of current bob process */
   XBT_INFO("   Zone property: author -> %s", root->get_property("author"));
 
   /* Get the property list of current bob process */
-  std::unordered_map<std::string, std::string>* props = simgrid::s4u::Actor::self()->get_properties();
+  const std::unordered_map<std::string, std::string>* props = simgrid::s4u::Actor::self()->get_properties();
   const char* noexist = "UnknownProcessProp";
   XBT_ATTRIB_UNUSED const char* value;
 
   const char* noexist = "UnknownProcessProp";
   XBT_ATTRIB_UNUSED const char* value;
 
index eaad97d..ef9b53c 100644 (file)
@@ -61,7 +61,7 @@ public:
 
   /** @brief Make a host within that NetZone */
   simgrid::s4u::Host* create_host(const char* name, const std::vector<double>& speed_per_pstate, int core_count,
 
   /** @brief Make a host within that NetZone */
   simgrid::s4u::Host* create_host(const char* name, const std::vector<double>& speed_per_pstate, int core_count,
-                                  std::map<std::string, std::string>* props);
+                                  const std::map<std::string, std::string>* props);
   /** @brief Creates a new route in this NetZone */
   virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
                                 std::vector<resource::LinkImpl*>& link_list, bool symmetrical);
   /** @brief Creates a new route in this NetZone */
   virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
                                 std::vector<resource::LinkImpl*>& link_list, bool symmetrical);
index 1dc179f..8e48a17 100644 (file)
@@ -289,7 +289,7 @@ public:
   kernel::actor::ActorImpl* get_impl() const { return pimpl_; }
 
   /** Retrieve the property value (or nullptr if not set) */
   kernel::actor::ActorImpl* get_impl() const { return pimpl_; }
 
   /** Retrieve the property value (or nullptr if not set) */
-  std::unordered_map<std::string, std::string>*
+  const std::unordered_map<std::string, std::string>*
   get_properties() const; // FIXME: do not export the map, but only the keys or something
   const char* get_property(const std::string& key) const;
   void set_property(const std::string& key, const std::string& value);
   get_properties() const; // FIXME: do not export the map, but only the keys or something
   const char* get_property(const std::string& key) const;
   void set_property(const std::string& key, const std::string& value);
index ea0afe0..f4d7550 100644 (file)
@@ -99,7 +99,7 @@ public:
 
   const char* get_property(const std::string& key) const;
   void set_property(const std::string& key, const std::string& value);
 
   const char* get_property(const std::string& key) const;
   void set_property(const std::string& key, const std::string& value);
-  std::unordered_map<std::string, std::string>* get_properties();
+  const std::unordered_map<std::string, std::string>* get_properties() const;
 
   void set_state_profile(kernel::profile::Profile* p);
   void set_speed_profile(kernel::profile::Profile* p);
 
   void set_state_profile(kernel::profile::Profile* p);
   void set_speed_profile(kernel::profile::Profile* p);
index 74fb9e9..85b5e1e 100644 (file)
@@ -93,7 +93,7 @@ public:
    * The profile must contain absolute values */
   void set_latency_profile(kernel::profile::Profile* profile);
 
    * The profile must contain absolute values */
   void set_latency_profile(kernel::profile::Profile* profile);
 
-  const char* get_property(const std::string& key);
+  const char* get_property(const std::string& key) const;
   void set_property(const std::string& key, const std::string& value);
 
   /* The signals */
   void set_property(const std::string& key, const std::string& value);
 
   /* The signals */
index 8004e96..e41fed0 100644 (file)
@@ -49,12 +49,12 @@ private:
 
 public:
   /** Get the properties assigned to a netzone */
 
 public:
   /** Get the properties assigned to a netzone */
-  std::unordered_map<std::string, std::string>* get_properties();
+  const std::unordered_map<std::string, std::string>* get_properties() const;
 
   std::vector<NetZone*> get_children();
 
   /** Retrieve the property value (or nullptr if not set) */
 
   std::vector<NetZone*> get_children();
 
   /** Retrieve the property value (or nullptr if not set) */
-  const char* get_property(const std::string& key);
+  const char* get_property(const std::string& key) const;
   void set_property(const std::string& key, const std::string& value);
 
   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
   void set_property(const std::string& key, const std::string& value);
 
   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
index 09c09e2..9bfa5ad 100644 (file)
@@ -56,8 +56,8 @@ public:
   Host* get_host() { return attached_to_; };
   void set_host(Host* host) { attached_to_ = host; }
 
   Host* get_host() { return attached_to_; };
   void set_host(Host* host) { attached_to_ = host; }
 
-  std::unordered_map<std::string, std::string>* get_properties();
-  const char* get_property(const std::string& key);
+  const std::unordered_map<std::string, std::string>* get_properties() const;
+  const char* get_property(const std::string& key) const;
   void set_property(const std::string&, const std::string& value);
 
   void set_data(void* data) { userdata_ = data; }
   void set_property(const std::string&, const std::string& value);
 
   void set_data(void* data) { userdata_ = data; }
index cce43fc..9a646da 100644 (file)
@@ -70,7 +70,7 @@ ActorImpl::~ActorImpl() = default;
  */
 
 ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* host,
  */
 
 ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* host,
-                               std::unordered_map<std::string, std::string>* properties)
+                               const std::unordered_map<std::string, std::string>* properties)
 {
   // This is mostly a copy/paste from create(), it'd be nice to share some code between those two functions.
 
 {
   // This is mostly a copy/paste from create(), it'd be nice to share some code between those two functions.
 
@@ -472,7 +472,7 @@ ActorImpl* ActorImpl::start(const simix::ActorCode& code)
 }
 
 ActorImplPtr ActorImpl::create(const std::string& name, const simix::ActorCode& code, void* data, s4u::Host* host,
 }
 
 ActorImplPtr ActorImpl::create(const std::string& name, const simix::ActorCode& code, void* data, s4u::Host* host,
-                               std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor)
+                               const std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor)
 {
   XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname());
 
 {
   XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname());
 
index c6324ec..a1d027f 100644 (file)
@@ -105,9 +105,9 @@ public:
   ActorImpl* start(const simix::ActorCode& code);
 
   static ActorImplPtr create(const std::string& name, const simix::ActorCode& code, void* data, s4u::Host* host,
   ActorImpl* start(const simix::ActorCode& code);
 
   static ActorImplPtr create(const std::string& name, const simix::ActorCode& code, void* data, s4u::Host* host,
-                             std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor);
+                             const std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor);
   static ActorImplPtr attach(const std::string& name, void* data, s4u::Host* host,
   static ActorImplPtr attach(const std::string& name, void* data, s4u::Host* host,
-                             std::unordered_map<std::string, std::string>* properties);
+                             const std::unordered_map<std::string, std::string>* properties);
   static void detach();
   void cleanup();
   void exit();
   static void detach();
   void cleanup();
   void exit();
@@ -133,7 +133,7 @@ public:
   void* data                                                               = nullptr;
   s4u::Host* host                                                          = nullptr;
   double kill_time                                                         = 0.0;
   void* data                                                               = nullptr;
   s4u::Host* host                                                          = nullptr;
   double kill_time                                                         = 0.0;
-  std::shared_ptr<std::unordered_map<std::string, std::string>> properties = nullptr;
+  std::shared_ptr<const std::unordered_map<std::string, std::string>> properties = nullptr;
   bool auto_restart                                                        = false;
   bool daemon_                                                             = false;
   ProcessArg()                                                             = default;
   bool auto_restart                                                        = false;
   bool daemon_                                                             = false;
   ProcessArg()                                                             = default;
index b87a8dd..babab5a 100644 (file)
@@ -93,7 +93,7 @@ int NetZoneImpl::get_host_count()
 }
 
 simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, const std::vector<double>& speed_per_pstate,
 }
 
 simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, const std::vector<double>& speed_per_pstate,
-                                             int coreAmount, std::map<std::string, std::string>* props)
+                                             int coreAmount, const std::map<std::string, std::string>* props)
 {
   simgrid::s4u::Host* res = new simgrid::s4u::Host(name);
 
 {
   simgrid::s4u::Host* res = new simgrid::s4u::Host(name);
 
index 953763c..fe048a5 100644 (file)
@@ -232,7 +232,7 @@ void Actor::kill_all()
   simix::simcall([self] { self->kill_all(); });
 }
 
   simix::simcall([self] { self->kill_all(); });
 }
 
-std::unordered_map<std::string, std::string>* Actor::get_properties() const
+const std::unordered_map<std::string, std::string>* Actor::get_properties() const
 {
   return pimpl_->get_properties();
 }
 {
   return pimpl_->get_properties();
 }
@@ -525,7 +525,7 @@ 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_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
   xbt_dict_t as_dict                        = xbt_dict_new_homogeneous(xbt_free_f);
-  std::unordered_map<std::string, std::string>* props = actor->get_properties();
+  const std::unordered_map<std::string, std::string>* props = actor->get_properties();
   if (props == nullptr)
     return nullptr;
   for (auto const& kv : *props) {
   if (props == nullptr)
     return nullptr;
   for (auto const& kv : *props) {
index 85ea7a3..2af9129 100644 (file)
@@ -165,9 +165,9 @@ void Host::route_to(Host* dest, std::vector<kernel::resource::LinkImpl*>& links,
 }
 
 /** Get the properties assigned to a host */
 }
 
 /** Get the properties assigned to a host */
-std::unordered_map<std::string, std::string>* Host::get_properties()
+const std::unordered_map<std::string, std::string>* Host::get_properties() const
 {
 {
-  return simix::simcall([this] { return this->pimpl_->get_properties(); });
+  return this->pimpl_->get_properties();
 }
 
 /** Retrieve the property value (or nullptr if not set) */
 }
 
 /** Retrieve the property value (or nullptr if not set) */
@@ -505,7 +505,7 @@ int sg_host_is_off(sg_host_t host)
 xbt_dict_t sg_host_get_properties(sg_host_t host)
 {
   xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
 xbt_dict_t sg_host_get_properties(sg_host_t host)
 {
   xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
-  std::unordered_map<std::string, std::string>* props = host->get_properties();
+  const std::unordered_map<std::string, std::string>* props = host->get_properties();
   if (props == nullptr)
     return nullptr;
   for (auto const& elm : *props) {
   if (props == nullptr)
     return nullptr;
   for (auto const& elm : *props) {
@@ -584,7 +584,7 @@ void sg_host_dump(sg_host_t host)
   XBT_INFO("Displaying host %s", host->get_cname());
   XBT_INFO("  - speed: %.0f", host->get_speed());
   XBT_INFO("  - available speed: %.2f", sg_host_get_available_speed(host));
   XBT_INFO("Displaying host %s", host->get_cname());
   XBT_INFO("  - speed: %.0f", host->get_speed());
   XBT_INFO("  - available speed: %.2f", sg_host_get_available_speed(host));
-  std::unordered_map<std::string, std::string>* props = host->get_properties();
+  const std::unordered_map<std::string, std::string>* props = host->get_properties();
 
   if (not props->empty()) {
     XBT_INFO("  - properties:");
 
   if (not props->empty()) {
     XBT_INFO("  - properties:");
index 456c57d..866436c 100644 (file)
@@ -105,7 +105,7 @@ void Link::set_latency_profile(kernel::profile::Profile* trace)
   simgrid::simix::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); });
 }
 
   simgrid::simix::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); });
 }
 
-const char* Link::get_property(const std::string& key)
+const char* Link::get_property(const std::string& key) const
 {
   return this->pimpl_->get_property(key);
 }
 {
   return this->pimpl_->get_property(key);
 }
index a039355..b17dd18 100644 (file)
@@ -27,16 +27,18 @@ NetZone::~NetZone()
 {
 }
 
 {
 }
 
-std::unordered_map<std::string, std::string>* NetZone::get_properties()
+const std::unordered_map<std::string, std::string>* NetZone::get_properties() const
 {
 {
-  return simix::simcall([this] { return &properties_; });
+  return &properties_;
 }
 
 /** Retrieve the property value (or nullptr if not set) */
 }
 
 /** Retrieve the property value (or nullptr if not set) */
-const char* NetZone::get_property(const std::string& key)
+const char* NetZone::get_property(const std::string& key) const
 {
 {
-  return properties_.at(key).c_str();
+  auto prop = properties_.find(key);
+  return prop == properties_.end() ? nullptr : prop->second.c_str();
 }
 }
+
 void NetZone::set_property(const std::string& key, const std::string& value)
 {
   simix::simcall([this, &key, &value] { properties_[key] = value; });
 void NetZone::set_property(const std::string& key, const std::string& value)
 {
   simix::simcall([this, &key, &value] { properties_[key] = value; });
index 0be7985..8de6680 100644 (file)
@@ -41,12 +41,12 @@ const char* Storage::get_type()
   return pimpl_->typeId_.c_str();
 }
 
   return pimpl_->typeId_.c_str();
 }
 
-std::unordered_map<std::string, std::string>* Storage::get_properties()
+const std::unordered_map<std::string, std::string>* Storage::get_properties() const
 {
 {
-  return simix::simcall([this] { return pimpl_->get_properties(); });
+  return pimpl_->get_properties();
 }
 
 }
 
-const char* Storage::get_property(const std::string& key)
+const char* Storage::get_property(const std::string& key) const
 {
   return this->pimpl_->get_property(key);
 }
 {
   return this->pimpl_->get_property(key);
 }
@@ -118,7 +118,7 @@ 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_assert((storage != nullptr), "Invalid parameters (storage is nullptr)");
   xbt_dict_t as_dict                        = xbt_dict_new_homogeneous(xbt_free_f);
-  std::unordered_map<std::string, std::string>* props = storage->get_properties();
+  const std::unordered_map<std::string, std::string>* props = storage->get_properties();
   if (props == nullptr)
     return nullptr;
   for (auto const& elm : *props) {
   if (props == nullptr)
     return nullptr;
   for (auto const& elm : *props) {
index a5bd802..8b002a4 100644 (file)
@@ -26,7 +26,7 @@ void PropertyHolder::set_property(const std::string& key, const std::string& val
 }
 
 /** @brief Return the whole set of properties. Don't mess with it, dude! */
 }
 
 /** @brief Return the whole set of properties. Don't mess with it, dude! */
-std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
+const std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
 {
   if (not properties_)
     properties_.reset(new std::unordered_map<std::string, std::string>);
 {
   if (not properties_)
     properties_.reset(new std::unordered_map<std::string, std::string>);
index a88589b..27ae7a6 100644 (file)
@@ -27,10 +27,7 @@ public:
   const char* get_property(const std::string& key) const;
   void set_property(const std::string& id, const std::string& value);
 
   const char* get_property(const std::string& key) const;
   void set_property(const std::string& id, const std::string& value);
 
-  /* FIXME: This should not be exposed, as users may do bad things with the map they got (it's not a copy).
-   * But some user API expose this call so removing it is not so easy.
-   */
-  std::unordered_map<std::string, std::string>* get_properties();
+  const std::unordered_map<std::string, std::string>* get_properties();
 
 private:
   std::unique_ptr<std::unordered_map<std::string, std::string>> properties_ = nullptr;
 
 private:
   std::unique_ptr<std::unordered_map<std::string, std::string>> properties_ = nullptr;
index 7e2e985..f5fb17f 100644 (file)
@@ -13,7 +13,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(storage, "Messages specific for this simulation");
 
 static void display_storage_properties(simgrid::s4u::Storage* storage)
 {
 
 static void display_storage_properties(simgrid::s4u::Storage* storage)
 {
-  std::unordered_map<std::string, std::string>* props = storage->get_properties();
+  const std::unordered_map<std::string, std::string>* props = storage->get_properties();
   if (not props->empty()) {
     XBT_INFO("\tProperties of mounted storage: %s", storage->get_cname());
 
   if (not props->empty()) {
     XBT_INFO("\tProperties of mounted storage: %s", storage->get_cname());
 
index 8cc8816..14fe8b0 100644 (file)
@@ -56,9 +56,6 @@ $ ./storage_client_server$EXEEXT ${platfdir}/storage/storage.xml "--log=root.fmt
 > [  1.207952] (server@alice)  Storage name: Disk2, mount name: c:
 > [  1.207952] (server@alice)          Free size: 534479367024 bytes
 > [  1.207952] (server@alice)          Used size: 2391544976 bytes
 > [  1.207952] (server@alice)  Storage name: Disk2, mount name: c:
 > [  1.207952] (server@alice)          Free size: 534479367024 bytes
 > [  1.207952] (server@alice)          Used size: 2391544976 bytes
-> [  1.207952] (client@bob) *** GET/SET DATA for storage element: Disk1 ***
-> [  1.207952] (client@bob) Get data: 'No User Data'
-> [  1.207952] (client@bob)    Set and get data: 'Some data'
 > [  1.207952] (server@alice)  No property attached.
 > [  1.207952] (server@alice) *** Dump a storage element ***
 > [  1.207952] (server@alice) Print the content of the storage element: Disk2
 > [  1.207952] (server@alice)  No property attached.
 > [  1.207952] (server@alice) *** Dump a storage element ***
 > [  1.207952] (server@alice) Print the content of the storage element: Disk2
@@ -102,6 +99,9 @@ $ ./storage_client_server$EXEEXT ${platfdir}/storage/storage.xml "--log=root.fmt
 > [  1.207952] (server@alice)  \Windows\winhlp32.exe size: 10752 bytes
 > [  1.207952] (server@alice)  \Windows\write.exe size: 10752 bytes
 > [  1.207952] (server@alice) Storage Disk1 is attached to bob
 > [  1.207952] (server@alice)  \Windows\winhlp32.exe size: 10752 bytes
 > [  1.207952] (server@alice)  \Windows\write.exe size: 10752 bytes
 > [  1.207952] (server@alice) Storage Disk1 is attached to bob
+> [  1.207952] (client@bob) *** GET/SET DATA for storage element: Disk1 ***
+> [  1.207952] (client@bob) Get data: 'No User Data'
+> [  1.207952] (client@bob)    Set and get data: 'Some data'
 > [  1.207952] (server@alice) Storage Disk2 is attached to alice
 > [  1.207952] (server@alice) Storage Disk3 is attached to carl
 > [  1.207952] (server@alice) Storage Disk4 is attached to denise
 > [  1.207952] (server@alice) Storage Disk2 is attached to alice
 > [  1.207952] (server@alice) Storage Disk3 is attached to carl
 > [  1.207952] (server@alice) Storage Disk4 is attached to denise
index 844e307..ce9155b 100644 (file)
@@ -42,7 +42,6 @@ static void create_environment(xbt_os_timer_t parse_time, const char *platformFi
 
 static void dump_hosts()
 {
 
 static void dump_hosts()
 {
-  std::unordered_map<std::string, std::string>* props = nullptr;
   unsigned int totalHosts = sg_host_count();
   sg_host_t* hosts        = sg_host_list();
   std::sort(hosts, hosts + totalHosts,
   unsigned int totalHosts = sg_host_count();
   sg_host_t* hosts        = sg_host_list();
   std::sort(hosts, hosts + totalHosts,
@@ -50,7 +49,7 @@ static void dump_hosts()
 
   for (unsigned int i = 0; i < totalHosts; i++) {
     std::printf("  <host id=\"%s\" speed=\"%.0f\"", hosts[i]->get_cname(), sg_host_speed(hosts[i]));
 
   for (unsigned int i = 0; i < totalHosts; i++) {
     std::printf("  <host id=\"%s\" speed=\"%.0f\"", hosts[i]->get_cname(), sg_host_speed(hosts[i]));
-    props = hosts[i]->get_properties();
+    const std::unordered_map<std::string, std::string>* props = hosts[i]->get_properties();
     if (hosts[i]->get_core_count() > 1) {
       std::printf(" core=\"%d\"", hosts[i]->get_core_count());
     }
     if (hosts[i]->get_core_count() > 1) {
       std::printf(" core=\"%d\"", hosts[i]->get_core_count());
     }