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"
10 #include "src/kernel/actor/ActorImpl.hpp"
15 xbt::signal<void(Io const&)> Io::on_start;
16 xbt::signal<void(Io const&)> Io::on_completion;
18 Io::Io(kernel::activity::IoImplPtr pimpl)
23 void Io::complete(Activity::State state)
25 Activity::complete(state);
31 auto pimpl = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
32 return IoPtr(pimpl->get_iface());
37 kernel::actor::simcall(
38 [this] { (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)).set_name(get_name()).start(); });
43 state_ = State::STARTED;
50 return this->wait_for(-1);
53 Io* Io::wait_for(double timeout)
55 if (state_ == State::INITED)
58 kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
59 kernel::actor::simcall_blocking([this, issuer, timeout] { this->get_impl()->wait_for(issuer, timeout); });
60 complete(state_ = State::FINISHED);
64 IoPtr Io::set_disk(const_sg_disk_t disk)
66 xbt_assert(state_ == State::INITED || state_ == State::STARTING, "Cannot set disk once the Io is started");
68 kernel::actor::simcall(
69 [this, disk] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->set_disk(disk->get_impl()); });
71 // Setting the disk may allow to start the activity, let's try
72 if (state_ == State::STARTING)
78 IoPtr Io::set_size(sg_size_t size)
80 xbt_assert(state_ == State::INITED || state_ == State::STARTING, "Cannot set size once the Io is started");
81 kernel::actor::simcall(
82 [this, size] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->set_size(size); });
83 Activity::set_remaining(size);
87 IoPtr Io::set_op_type(OpType type)
89 xbt_assert(state_ == State::INITED || state_ == State::STARTING, "Cannot set size once the Io is started");
90 kernel::actor::simcall(
91 [this, type] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->set_type(type); });
95 /** @brief Returns the amount of flops that remain to be done */
96 double Io::get_remaining() const
98 return kernel::actor::simcall(
99 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
102 sg_size_t Io::get_performed_ioops() const
104 return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops();
107 bool Io::is_assigned() const
109 return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_disk() != nullptr;
113 } // namespace simgrid