Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove constraint from LinkImpl ctor
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 5 Mar 2021 13:56:43 +0000 (14:56 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 5 Mar 2021 13:56:43 +0000 (14:56 +0100)
src/surf/network_cm02.cpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/network_ns3.cpp
src/surf/network_wifi.cpp
src/surf/ptask_L07.cpp

index ac6e216..4f8dbb5 100644 (file)
@@ -97,10 +97,10 @@ LinkImpl* NetworkCm02Model::create_link(const std::string& name, const std::vect
                                         s4u::Link::SharingPolicy policy)
 {
   if (policy == s4u::Link::SharingPolicy::WIFI)
-    return new NetworkWifiLink(name, bandwidths, get_maxmin_system());
+    return (new NetworkWifiLink(name, bandwidths, get_maxmin_system()))->set_model(this);
 
   xbt_assert(bandwidths.size() == 1, "Non-WIFI links must use only 1 bandwidth.");
-  return new NetworkCm02Link(name, bandwidths[0], policy, get_maxmin_system());
+  return (new NetworkCm02Link(name, bandwidths[0], policy, get_maxmin_system()))->set_model(this);
 }
 
 void NetworkCm02Model::update_actions_state_lazy(double now, double /*delta*/)
@@ -310,10 +310,11 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz
  ************/
 NetworkCm02Link::NetworkCm02Link(const std::string& name, double bandwidth, s4u::Link::SharingPolicy policy,
                                  kernel::lmm::System* system)
-    : LinkImpl(name, system->constraint_new(this, sg_bandwidth_factor * bandwidth))
+    : LinkImpl(name)
 {
   bandwidth_.scale = 1.0;
   bandwidth_.peak  = bandwidth;
+  this->set_constraint(system->constraint_new(this, sg_bandwidth_factor * bandwidth));
 
   if (policy == s4u::Link::SharingPolicy::FATPIPE)
     get_constraint()->unshare();
index 23a464a..f33fe69 100644 (file)
@@ -73,9 +73,8 @@ double NetworkModel::next_occurring_event_full(double now)
  * Resource *
  ************/
 
-LinkImpl::LinkImpl(const std::string& name, lmm::Constraint* constraint) : Resource_T(name), piface_(this)
+LinkImpl::LinkImpl(const std::string& name) : Resource_T(name), piface_(this)
 {
-  this->set_constraint(constraint);
   if (name != "__loopback__")
     xbt_assert(not s4u::Link::by_name_or_null(name), "Link '%s' declared several times in the platform.", name.c_str());
 
@@ -156,7 +155,6 @@ void LinkImpl::turn_off()
 
 void LinkImpl::seal()
 {
-  this->set_model(surf_network_model);
   Resource::seal();
   simgrid::s4u::Link::on_creation(*get_iface());
 }
index 51e0d0e..3c749be 100644 (file)
@@ -110,7 +110,7 @@ class LinkImpl : public Resource_T<LinkImpl>, public xbt::PropertyHolder {
   s4u::Link piface_;
 
 protected:
-  LinkImpl(const std::string& name, lmm::Constraint* constraint);
+  LinkImpl(const std::string& name);
   LinkImpl(const LinkImpl&) = delete;
   LinkImpl& operator=(const LinkImpl&) = delete;
   ~LinkImpl() override                 = default; // Use destroy() instead of this destructor.
index cf95459..569b6c6 100644 (file)
@@ -433,7 +433,7 @@ void NetworkNS3Model::update_actions_state(double now, double delta)
  ************/
 
 LinkNS3::LinkNS3(const std::string& name, double bandwidth, s4u::Link::SharingPolicy policy)
-    : LinkImpl(name, nullptr), sharing_policy_(policy)
+    : LinkImpl(name), sharing_policy_(policy)
 {
   bandwidth_.peak = bandwidth;
 }
index ccbbf0a..a39a7ca 100644 (file)
@@ -18,8 +18,9 @@ namespace resource {
  ************/
 
 NetworkWifiLink::NetworkWifiLink(const std::string& name, std::vector<double> bandwidths, lmm::System* system)
-    : LinkImpl(name, system->constraint_new(this, 1))
+    : LinkImpl(name)
 {
+  this->set_constraint(system->constraint_new(this, 1));
   for (auto bandwidth : bandwidths)
     bandwidths_.push_back({bandwidth, 1.0, nullptr});
 }
index 5799ac2..de2019e 100644 (file)
@@ -247,16 +247,6 @@ CpuL07::CpuL07(CpuL07Model* model, simgrid::s4u::Host* host, const std::vector<d
 
 CpuL07::~CpuL07()=default;
 
-LinkL07::LinkL07(const std::string& name, double bandwidth, s4u::Link::SharingPolicy policy,
-                 kernel::lmm::System* system)
-    : LinkImpl(name, system->constraint_new(this, bandwidth))
-{
-  bandwidth_.peak = bandwidth;
-
-  if (policy == s4u::Link::SharingPolicy::FATPIPE)
-    get_constraint()->unshare();
-}
-
 kernel::resource::CpuAction* CpuL07::execution_start(double size)
 {
   std::vector<s4u::Host*> host_list = {get_iface()};
@@ -301,6 +291,17 @@ void CpuL07::on_speed_change()
   Cpu::on_speed_change();
 }
 
+LinkL07::LinkL07(const std::string& name, double bandwidth, s4u::Link::SharingPolicy policy,
+                 kernel::lmm::System* system)
+    : LinkImpl(name)
+{
+  this->set_constraint(system->constraint_new(this, bandwidth));
+  bandwidth_.peak = bandwidth;
+
+  if (policy == s4u::Link::SharingPolicy::FATPIPE)
+    get_constraint()->unshare();
+}
+
 bool LinkL07::is_used() const
 {
   return get_model()->get_maxmin_system()->constraint_used(get_constraint());