1 /* Copyright (c) 2018. 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/Io.hpp"
7 #include "simgrid/s4u/Storage.hpp"
8 #include "src/kernel/activity/IoImpl.hpp"
9 #include "src/simix/smx_io_private.hpp"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
19 pimpl_ = simix::simcall([this] { return SIMIX_io_start(name_, size_, storage_, type_); });
20 state_ = State::STARTED;
24 Activity* Io::cancel()
26 simgrid::simix::simcall([this] { dynamic_cast<kernel::activity::IoImpl*>(pimpl_.get())->cancel(); });
27 state_ = State::CANCELED;
33 simcall_io_wait(pimpl_);
34 state_ = State::FINISHED;
38 Activity* Io::wait(double timeout)
44 /** @brief Returns the amount of flops that remain to be done */
45 double Io::get_remaining()
47 return simgrid::simix::simcall(
48 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
51 sg_size_t Io::get_performed_ioops()
53 return simgrid::simix::simcall(
54 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
57 IoPtr Io::set_io_type(OpType type)
59 xbt_assert(state_ == State::INITED, "Cannot change the name of an exec after its start");
64 void intrusive_ptr_release(simgrid::s4u::Io* i)
66 if (i->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
67 std::atomic_thread_fence(std::memory_order_acquire);
72 void intrusive_ptr_add_ref(simgrid::s4u::Io* i)
74 i->refcount_.fetch_add(1, std::memory_order_relaxed);
77 } // namespace simgrid