From ba5cf16371aed445f20533645ca049990862630a Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Tue, 30 Mar 2021 19:58:32 +0200 Subject: [PATCH] Fix MC tests. Move back host name to s4u::Host. There, it's accessible by MC --- include/simgrid/s4u/Host.hpp | 8 +++++--- src/plugins/vm/s4u_VirtualMachine.cpp | 2 +- src/s4u/s4u_Host.cpp | 10 ---------- src/surf/HostImpl.cpp | 14 +++++++------- src/surf/HostImpl.hpp | 6 ------ 5 files changed, 13 insertions(+), 27 deletions(-) diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index b23efc3c63..2fec149e8e 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -46,7 +46,7 @@ class XBT_PUBLIC Host : public xbt::Extendable { surf::HostImpl* const pimpl_; public: - explicit Host(surf::HostImpl* pimpl) : pimpl_(pimpl) {} + explicit Host(const std::string& name, surf::HostImpl* pimpl) : pimpl_(pimpl), name_(name) {} protected: virtual ~Host(); // Call destroy() instead of manually deleting it. @@ -79,9 +79,9 @@ public: static Host* current(); /** Retrieves the name of that host as a C++ string */ - xbt::string const& get_name() const; + xbt::string const& get_name() const { return name_; }; /** Retrieves the name of that host as a C string */ - const char* get_cname() const; + const char* get_cname() const { return name_.c_str(); }; kernel::routing::NetPoint* get_netpoint() const { return pimpl_netpoint_; } @@ -190,6 +190,8 @@ public: surf::HostImpl* get_impl() const { return pimpl_; } private: + /* Host name must be kept in the s4u side to be accessible by MC process */ + xbt::string name_{"noname"}; kernel::routing::NetPoint* pimpl_netpoint_ = nullptr; public: diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 7450b709cd..4b966f794d 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -30,7 +30,7 @@ VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host } VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host, int core_amount, size_t ramsize) - : Host(new vm::VirtualMachineImpl(name, this, physical_host, core_amount, ramsize)) + : Host(name, new vm::VirtualMachineImpl(name, this, physical_host, core_amount, ramsize)) , pimpl_vm_(dynamic_cast(Host::get_impl())) { XBT_DEBUG("Create VM %s", get_cname()); diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 2689b56341..bb56640b9d 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -74,16 +74,6 @@ Host* Host::current() return self->get_host(); } -xbt::string const& Host::get_name() const -{ - return this->pimpl_->get_name(); -} - -const char* Host::get_cname() const -{ - return this->pimpl_->get_cname(); -} - void Host::turn_on() { if (not is_on()) { diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 9b8ec04df4..8919977f99 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -25,16 +25,16 @@ namespace surf { /************ * Resource * ************/ -HostImpl::HostImpl(const std::string& name, s4u::Host* piface) : piface_(this), name_(name) +HostImpl::HostImpl(const std::string& name, s4u::Host* piface) : piface_(name, this) { - xbt_assert(s4u::Host::by_name_or_null(name_) == nullptr, "Refusing to create a second host named '%s'.", get_cname()); - s4u::Engine::get_instance()->host_register(name_, piface); + xbt_assert(s4u::Host::by_name_or_null(name) == nullptr, "Refusing to create a second host named '%s'.", name.c_str()); + s4u::Engine::get_instance()->host_register(name, piface); } -HostImpl::HostImpl(const std::string& name) : piface_(this), name_(name) +HostImpl::HostImpl(const std::string& name) : piface_(name, this) { - xbt_assert(s4u::Host::by_name_or_null(name_) == nullptr, "Refusing to create a second host named '%s'.", get_cname()); - s4u::Engine::get_instance()->host_register(name_, &piface_); + xbt_assert(s4u::Host::by_name_or_null(name) == nullptr, "Refusing to create a second host named '%s'.", name.c_str()); + s4u::Engine::get_instance()->host_register(name, &piface_); } HostImpl::~HostImpl() @@ -63,7 +63,7 @@ HostImpl::~HostImpl() void HostImpl::destroy() { s4u::Host::on_destruction(*this->get_iface()); - s4u::Engine::get_instance()->host_unregister(std::string(name_)); + s4u::Engine::get_instance()->host_unregister(std::string(get_iface()->get_name())); delete this; } diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 2429c3d91b..1b08609b11 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -50,7 +50,6 @@ class XBT_PRIVATE HostImpl : public xbt::PropertyHolder { std::vector actors_at_boot_; s4u::Host piface_; std::vector disks_; - xbt::string name_{"noname"}; protected: virtual ~HostImpl(); // Use destroy() instead of this destructor. @@ -70,11 +69,6 @@ public: virtual const s4u::Host* get_iface() const { return &piface_; } virtual s4u::Host* get_iface() { return &piface_; } - /** Retrieves the name of that host as a C++ string */ - xbt::string const& get_name() const { return name_; } - /** Retrieves the name of that host as a C string */ - const char* get_cname() const { return name_.c_str(); } - void turn_on() const; void turn_off(const kernel::actor::ActorImpl* issuer); std::vector get_all_actors(); -- 2.20.1