1 /* Copyright (c) 2018-2020. 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/Disk.hpp"
7 #include "simgrid/s4u/Io.hpp"
8 #include "simgrid/s4u/Storage.hpp"
9 #include "src/kernel/activity/IoImpl.hpp"
15 Io::Io(sg_disk_t disk, sg_size_t size, OpType type) : disk_(disk), size_(size), type_(type)
17 Activity::set_remaining(size_);
18 pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
21 Io::Io(sg_storage_t storage, sg_size_t size, OpType type) : storage_(storage), size_(size), type_(type)
23 Activity::set_remaining(size_);
24 pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
29 kernel::actor::simcall([this] {
31 (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
33 .set_storage(storage_->get_impl())
38 (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
40 .set_disk(disk_->get_impl())
46 state_ = State::STARTED;
52 simgrid::kernel::actor::simcall([this] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->cancel(); });
53 state_ = State::CANCELED;
59 return this->wait_for(-1);
62 Io* Io::wait_for(double timeout)
64 if (state_ == State::INITED)
66 simcall_io_wait(pimpl_, timeout);
67 state_ = State::FINISHED;
68 this->release_dependencies();
74 xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING ||
75 state_ == State::FINISHED);
77 if (state_ == State::FINISHED)
80 if (state_ == State::INITED || state_ == State::STARTING)
81 this->vetoable_start();
83 if (simcall_io_test(pimpl_)) {
84 state_ = State::FINISHED;
85 this->release_dependencies();
92 /** @brief Returns the amount of flops that remain to be done */
93 double Io::get_remaining()
95 return kernel::actor::simcall(
96 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
99 sg_size_t Io::get_performed_ioops()
101 return kernel::actor::simcall(
102 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
106 } // namespace simgrid