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/Actor.hpp"
7 #include "simgrid/s4u/Disk.hpp"
8 #include "simgrid/s4u/Io.hpp"
9 #include "simgrid/s4u/Storage.hpp"
10 #include "src/kernel/activity/IoImpl.hpp"
16 Io::Io(sg_disk_t disk, sg_size_t size, OpType type) : disk_(disk), size_(size), type_(type)
18 Activity::set_remaining(size_);
19 pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
22 Io::Io(sg_storage_t storage, sg_size_t size, OpType type) : storage_(storage), size_(size), type_(type)
24 Activity::set_remaining(size_);
25 pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
30 kernel::actor::simcall([this] {
32 (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
34 .set_storage(storage_->get_impl())
39 (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
41 .set_disk(disk_->get_impl())
47 state_ = State::STARTED;
53 simgrid::kernel::actor::simcall([this] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->cancel(); });
54 state_ = State::CANCELED;
60 return this->wait_for(-1);
63 Io* Io::wait_for(double timeout)
65 if (state_ == State::INITED)
68 kernel::actor::ActorImpl* issuer = Actor::self()->get_impl();
69 kernel::actor::simcall_blocking<void>([this, issuer, timeout] { this->get_impl()->wait_for(issuer, timeout); });
70 state_ = State::FINISHED;
71 this->release_dependencies();
75 /** @brief Returns the amount of flops that remain to be done */
76 double Io::get_remaining() const
78 return kernel::actor::simcall(
79 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
82 sg_size_t Io::get_performed_ioops() const
84 return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops();
88 } // namespace simgrid