From 8d9b5170925fd2a7873c619c5d6cdff8616f9bfc Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Thu, 8 Apr 2021 16:32:02 +0200 Subject: [PATCH] s4u: allows full single-line initialization seal() returns a pointer to the s4u object. Allows users to use the object after its seal, without having to do it in another line --- include/simgrid/s4u/Disk.hpp | 2 +- include/simgrid/s4u/Host.hpp | 2 +- include/simgrid/s4u/Link.hpp | 2 +- include/simgrid/s4u/NetZone.hpp | 2 +- src/s4u/s4u_Disk.cpp | 3 ++- src/s4u/s4u_Host.cpp | 3 ++- src/s4u/s4u_Link.cpp | 3 ++- src/s4u/s4u_Netzone.cpp | 3 ++- src/surf/sg_platf.cpp | 12 ++++++------ 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/simgrid/s4u/Disk.hpp b/include/simgrid/s4u/Disk.hpp index 0d051c802f..fa7b00953f 100644 --- a/include/simgrid/s4u/Disk.hpp +++ b/include/simgrid/s4u/Disk.hpp @@ -78,7 +78,7 @@ public: IoPtr write_async(sg_size_t size) const; sg_size_t write(sg_size_t size) const; - void seal(); + Disk* seal(); #ifndef DOXYGEN kernel::resource::DiskImpl* get_impl() const { return pimpl_; } diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index 834944e8f4..eee859606a 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -176,7 +176,7 @@ public: * @brief Seal this host * No more configuration is allowed after the seal */ - void seal(); + Host* seal(); #ifndef DOXYGEN XBT_ATTRIB_DEPRECATED_v331("Please use Comm::sendto()") void sendto(Host* dest, double byte_amount); diff --git a/include/simgrid/s4u/Link.hpp b/include/simgrid/s4u/Link.hpp index 284f82c15d..d15da44444 100644 --- a/include/simgrid/s4u/Link.hpp +++ b/include/simgrid/s4u/Link.hpp @@ -115,7 +115,7 @@ public: void turn_off(); bool is_on() const; - void seal(); + Link* seal(); /* The signals */ /** @brief Callback signal fired when a new Link is created */ diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index dd4db0df25..045a08948f 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -136,7 +136,7 @@ public: s4u::Link* create_link(const std::string& name, const std::vector& bandwidths); /** @brief Seal this netzone configuration */ - void seal(); + NetZone* seal(); private: /** @brief Auxiliary function to get list of LinkImpl */ diff --git a/src/s4u/s4u_Disk.cpp b/src/s4u/s4u_Disk.cpp index 07c2012222..ab870db20b 100644 --- a/src/s4u/s4u_Disk.cpp +++ b/src/s4u/s4u_Disk.cpp @@ -99,11 +99,12 @@ sg_size_t Disk::write(sg_size_t size) const return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops(); } -void Disk::seal() +Disk* Disk::seal() { kernel::actor::simcall([this]{ pimpl_->seal(); }); get_host()->add_disk(this); Disk::on_creation(*this); + return this; } } // namespace s4u } // namespace simgrid diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index c11256d4ee..0d114fdf86 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -347,10 +347,11 @@ void Host::execute(double flops, double priority) const this_actor::exec_init(flops)->set_priority(1 / priority)->vetoable_start()->wait(); } -void Host::seal() +Host* Host::seal() { kernel::actor::simcall([this]() { this->pimpl_->seal(); }); simgrid::s4u::Host::on_creation(*this); // notify the signal + return this; } } // namespace s4u diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index 373708bc68..41a19abdac 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -122,9 +122,10 @@ void Link::turn_off() { kernel::actor::simcall([this]() { this->pimpl_->turn_off(); }); } -void Link::seal() +Link* Link::seal() { kernel::actor::simcall([this]() { this->pimpl_->seal(); }); + return this; } bool Link::is_on() const diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index dc6f3d4d98..4f97b64206 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -143,9 +143,10 @@ void NetZone::extract_xbt_graph(const s_xbt_graph_t* graph, std::mapget_graph(graph, nodes, edges); } -void NetZone::seal() +NetZone* NetZone::seal() { kernel::actor::simcall([this] { pimpl_->seal(); }); + return this; } s4u::Host* NetZone::create_host(const std::string& name, const std::vector& speed_per_pstate) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 6319f16675..eef11b53d6 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -198,8 +198,8 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster simgrid::s4u::Link* loopback = current_zone->create_link(loopback_name, std::vector{cluster->loopback_bw}) ->set_sharing_policy(simgrid::s4u::Link::SharingPolicy::FATPIPE) - ->set_latency(cluster->loopback_lat); - loopback->seal(); + ->set_latency(cluster->loopback_lat) + ->seal(); current_zone->add_private_link_at(current_zone->node_pos(rankId), {loopback->get_impl(), loopback->get_impl()}); } @@ -209,8 +209,8 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster std::string limiter_name = std::string(link_id) + "_limiter"; XBT_DEBUG("", limiter_name.c_str(), cluster->limiter_link); - simgrid::s4u::Link* limiter = current_zone->create_link(limiter_name, std::vector{cluster->limiter_link}); - limiter->seal(); + simgrid::s4u::Link* limiter = + current_zone->create_link(limiter_name, std::vector{cluster->limiter_link})->seal(); current_zone->add_private_link_at(current_zone->node_pos_with_loopback(rankId), {limiter->get_impl(), limiter->get_impl()}); @@ -240,8 +240,8 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster simgrid::s4u::Link* backbone = current_zone->create_link(backbone_name, std::vector{cluster->bb_bw}) ->set_sharing_policy(cluster->bb_sharing_policy) - ->set_latency(cluster->bb_lat); - backbone->seal(); + ->set_latency(cluster->bb_lat) + ->seal(); routing_cluster_add_backbone(backbone->get_impl()); } -- 2.20.1