1 /* Copyright (c) 2018-2019. 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 simcall_io_wait(pimpl_, timeout);
65 state_ = State::FINISHED;
71 xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
73 if (state_ == State::FINISHED)
76 if (state_ == State::INITED)
79 if (simcall_io_test(pimpl_)) {
80 state_ = State::FINISHED;
87 /** @brief Returns the amount of flops that remain to be done */
88 double Io::get_remaining()
90 return kernel::actor::simcall(
91 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
94 sg_size_t Io::get_performed_ioops()
96 return kernel::actor::simcall(
97 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
101 } // namespace simgrid