X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/85313e62aa3ec8a2f1de00cb7da9df46588ea2c2..69fa210e4b6249f5bb59170c4bc78bb389cd4e57:/src/plugins/operation.cpp diff --git a/src/plugins/operation.cpp b/src/plugins/operation.cpp index 963bce0316..689bd0ce4c 100644 --- a/src/plugins/operation.cpp +++ b/src/plugins/operation.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "src/simgrid/module.hpp" @@ -125,6 +126,9 @@ void Operation::init() simgrid::s4u::Comm::on_completion_cb([](simgrid::s4u::Comm const& comm) { comm.extension()->operation_->complete(); }); + simgrid::s4u::Io::on_completion_cb([](simgrid::s4u::Io const& io) { + io.extension()->operation_->complete(); + }); } /** @ingroup plugin_operation @@ -350,6 +354,74 @@ CommOpPtr CommOp::set_bytes(double bytes) return this; } +/** + * @brief Default constructor. + */ +IoOp::IoOp(const std::string& name) : Operation(name) {} + +/** @ingroup plugin_operation + * @brief Smart Constructor. + */ +IoOpPtr IoOp::init(const std::string& name) +{ + return IoOpPtr(new IoOp(name)); +} + +/** @ingroup plugin_operation + * @brief Smart Constructor. + */ +IoOpPtr IoOp::init(const std::string& name, double bytes, s4u::Disk* disk, s4u::Io::OpType type) +{ + return init(name)->set_bytes(bytes)->set_disk(disk)->set_op_type(type); +} + +/** @ingroup plugin_operation + * @param disk The disk to set. + * @brief Set a new disk. + */ +IoOpPtr IoOp::set_disk(s4u::Disk* disk) +{ + kernel::actor::simcall_answered([this, disk] { disk_ = disk; }); + return this; +} + +/** @ingroup plugin_operation + * @param bytes The amount of bytes to set. + */ +IoOpPtr IoOp::set_bytes(double bytes) +{ + kernel::actor::simcall_answered([this, bytes] { amount_ = bytes; }); + return this; +} + +/** @ingroup plugin_operation */ +IoOpPtr IoOp::set_op_type(s4u::Io::OpType type) +{ + kernel::actor::simcall_answered([this, type] { type_ = type; }); + return this; +} + +void IoOp::execute() +{ + for (auto start_func : start_func_handlers_) + start_func(this); + Operation::on_start(this); + kernel::actor::simcall_answered([this] { + working_ = true; + queued_execs_ = std::max(queued_execs_ - 1, 0); + }); + s4u::IoPtr io = s4u::Io::init(); + io->set_name(name_); + io->set_size(amount_); + io->set_disk(disk_); + io->set_op_type(type_); + io->start(); + io->extension_set(new ExtendedAttributeActivity()); + io->extension()->operation_ = this; + kernel::actor::simcall_answered([this, io] { current_activity_ = io; }); +} + + } // namespace simgrid::plugins simgrid::xbt::Extension