1 /* Copyright (c) 2007-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 "src/kernel/activity/IoImpl.hpp"
7 #include "simgrid/kernel/resource/Action.hpp"
8 #include "src/simix/smx_io_private.hpp"
9 #include "src/surf/StorageImpl.hpp"
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_io);
16 IoImpl::IoImpl(std::string name, surf::StorageImpl* storage) : ActivityImpl(std::move(name)), storage_(storage)
18 this->state_ = SIMIX_RUNNING;
20 XBT_DEBUG("Create io impl %p", this);
25 if (surf_action_ != nullptr)
26 surf_action_->unref();
27 XBT_DEBUG("Destroy io %p", this);
30 IoImpl* IoImpl::start(sg_size_t size, simgrid::s4u::Io::OpType type)
32 surf_action_ = storage_->io_start(size, type);
33 surf_action_->set_data(this);
35 XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
36 simgrid::kernel::activity::IoImpl::on_start(this);
43 XBT_VERB("This exec %p is canceled", this);
44 if (surf_action_ != nullptr)
45 surf_action_->cancel();
48 double IoImpl::get_remaining()
50 return surf_action_ ? surf_action_->get_remains() : 0;
55 performed_ioops_ = surf_action_->get_cost();
56 switch (surf_action_->get_state()) {
57 case simgrid::kernel::resource::Action::State::FAILED:
58 state_ = SIMIX_FAILED;
60 case simgrid::kernel::resource::Action::State::FINISHED:
69 SIMIX_io_finish(this);
74 xbt::signal<void(IoImplPtr)> IoImpl::on_start;
75 xbt::signal<void(IoImplPtr)> IoImpl::on_completion;
77 } // namespace activity
79 } // namespace simgrid