1 /* Copyright (c) 2018-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u/Actor.hpp"
7 #include "simgrid/s4u/Disk.hpp"
8 #include "simgrid/s4u/Io.hpp"
9 #include "src/kernel/activity/IoImpl.hpp"
14 xbt::signal<void(Io const&)> Io::on_start;
15 xbt::signal<void(Io const&)> Io::on_completion;
19 pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
24 return IoPtr(new Io());
29 kernel::actor::simcall([this] {
30 (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
32 .set_disk(disk_->get_impl())
41 state_ = State::STARTED;
48 simgrid::kernel::actor::simcall([this] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->cancel(); });
49 state_ = State::CANCELED;
56 return this->wait_for(-1);
59 Io* Io::wait_for(double timeout)
61 if (state_ == State::INITED)
64 kernel::actor::ActorImpl* issuer = Actor::self()->get_impl();
65 kernel::actor::simcall_blocking<void>([this, issuer, timeout] { this->get_impl()->wait_for(issuer, timeout); });
66 state_ = State::FINISHED;
67 this->release_dependencies();
73 IoPtr Io::set_disk(sg_disk_t disk)
77 // Setting the disk may allow to start the activity, let's try
78 if (state_ == State::STARTING)
84 IoPtr Io::set_size(sg_size_t size)
87 Activity::set_remaining(size_);
91 IoPtr Io::set_op_type(OpType type)
97 /** @brief Returns the amount of flops that remain to be done */
98 double Io::get_remaining() const
100 return kernel::actor::simcall(
101 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
104 sg_size_t Io::get_performed_ioops() const
106 return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops();
110 } // namespace simgrid