From 3a76359d818d1d9c0b3dad7d552e5b32b4595335 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 5 Mar 2021 14:56:43 +0100 Subject: [PATCH] Remove constraint from LinkImpl ctor --- src/surf/network_cm02.cpp | 7 ++++--- src/surf/network_interface.cpp | 4 +--- src/surf/network_interface.hpp | 2 +- src/surf/network_ns3.cpp | 2 +- src/surf/network_wifi.cpp | 3 ++- src/surf/ptask_L07.cpp | 21 +++++++++++---------- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index ac6e21608f..4f8dbb58b6 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -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(); diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 23a464aa33..f33fe69971 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -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()); } diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index 51e0d0ec9d..3c749be205 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -110,7 +110,7 @@ class LinkImpl : public Resource_T, 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. diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index cf95459254..569b6c6d11 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -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; } diff --git a/src/surf/network_wifi.cpp b/src/surf/network_wifi.cpp index ccbbf0aea8..a39a7ca3fa 100644 --- a/src/surf/network_wifi.cpp +++ b/src/surf/network_wifi.cpp @@ -18,8 +18,9 @@ namespace resource { ************/ NetworkWifiLink::NetworkWifiLink(const std::string& name, std::vector 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}); } diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 5799ac2a6c..de2019e8a0 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -247,16 +247,6 @@ CpuL07::CpuL07(CpuL07Model* model, simgrid::s4u::Host* host, const std::vectorconstraint_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 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()); -- 2.20.1