Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way IO activities are initiated
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 2 Feb 2021 16:49:22 +0000 (17:49 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 2 Feb 2021 16:49:22 +0000 (17:49 +0100)
include/simgrid/s4u/Io.hpp
src/s4u/s4u_Disk.cpp
src/s4u/s4u_Io.cpp
src/s4u/s4u_Storage.cpp

index 90e4e92..a4ae965 100644 (file)
@@ -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<void(Io const&)> on_start;
   static xbt::signal<void(Io const&)> 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
index 989348e..10b19e4 100644 (file)
@@ -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)
index f391e55..524f300 100644 (file)
@@ -15,16 +15,14 @@ namespace s4u {
 xbt::signal<void(Io const&)> Io::on_start;
 xbt::signal<void(Io const&)> 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
 {
index 314be27..bf602dc 100644 (file)
@@ -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)