From d8019436f59c224efbe9da8a1b23e32a9f7c21a9 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 2 Feb 2021 17:49:22 +0100 Subject: [PATCH] Change the way IO activities are initiated --- include/simgrid/s4u/Io.hpp | 8 ++++++-- src/s4u/s4u_Disk.cpp | 2 +- src/s4u/s4u_Io.cpp | 33 ++++++++++++++++++++++++++++----- src/s4u/s4u_Storage.cpp | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/include/simgrid/s4u/Io.hpp b/include/simgrid/s4u/Io.hpp index 90e4e92da9..a4ae965e7a 100644 --- a/include/simgrid/s4u/Io.hpp +++ b/include/simgrid/s4u/Io.hpp @@ -29,8 +29,7 @@ private: sg_size_t size_ = 0; OpType type_ = OpType::READ; - explicit Io(sg_storage_t storage, sg_size_t size, OpType type); - explicit Io(sg_disk_t disk, sg_size_t size, OpType type); + Io(); public: #ifndef DOXYGEN @@ -43,6 +42,7 @@ public: static xbt::signal on_start; static xbt::signal on_completion; + static IoPtr init(); Io* start() override; Io* wait() override; Io* wait_for(double timeout) override; @@ -50,6 +50,10 @@ public: double get_remaining() const override; sg_size_t get_performed_ioops() const; + IoPtr set_disk(sg_disk_t disk); + IoPtr set_storage(sg_storage_t storage); + IoPtr set_size(sg_size_t size); + IoPtr set_op_type(OpType type); }; } // namespace s4u diff --git a/src/s4u/s4u_Disk.cpp b/src/s4u/s4u_Disk.cpp index 989348e4f4..10b19e4674 100644 --- a/src/s4u/s4u_Disk.cpp +++ b/src/s4u/s4u_Disk.cpp @@ -52,7 +52,7 @@ void Disk::set_property(const std::string& key, const std::string& value) IoPtr Disk::io_init(sg_size_t size, Io::OpType type) { - return IoPtr(new Io(this, size, type)); + return Io::init()->set_disk(this)->set_size(size)->set_op_type(type); } IoPtr Disk::read_async(sg_size_t size) diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp index f391e5524b..524f300ac1 100644 --- a/src/s4u/s4u_Io.cpp +++ b/src/s4u/s4u_Io.cpp @@ -15,16 +15,14 @@ namespace s4u { xbt::signal Io::on_start; xbt::signal Io::on_completion; -Io::Io(sg_disk_t disk, sg_size_t size, OpType type) : disk_(disk), size_(size), type_(type) +Io::Io() { - Activity::set_remaining(size_); pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl()); } -Io::Io(sg_storage_t storage, sg_size_t size, OpType type) : storage_(storage), size_(size), type_(type) +IoPtr Io::init() { - Activity::set_remaining(size_); - pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl()); + return IoPtr(new Io()); } Io* Io::start() @@ -81,6 +79,31 @@ Io* Io::wait_for(double timeout) return this; } +IoPtr Io::set_disk(sg_disk_t disk) +{ + disk_ = disk; + return this; +} + +IoPtr Io::set_storage(sg_storage_t storage) +{ + storage_ = storage; + return this; +} + +IoPtr Io::set_size(sg_size_t size) +{ + size_ = size; + Activity::set_remaining(size_); + return this; +} + +IoPtr Io::set_op_type(OpType type) +{ + type_ = type; + return this; +} + /** @brief Returns the amount of flops that remain to be done */ double Io::get_remaining() const { diff --git a/src/s4u/s4u_Storage.cpp b/src/s4u/s4u_Storage.cpp index 314be27664..bf602dcc50 100644 --- a/src/s4u/s4u_Storage.cpp +++ b/src/s4u/s4u_Storage.cpp @@ -58,7 +58,7 @@ void Storage::set_property(const std::string& key, const std::string& value) IoPtr Storage::io_init(sg_size_t size, Io::OpType type) { - return IoPtr(new Io(this, size, type)); + return Io::init()->set_storage(this)->set_size(size)->set_op_type(type); } IoPtr Storage::read_async(sg_size_t size) -- 2.20.1