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/Io.hpp"
7 #include "simgrid/s4u/Storage.hpp"
8 #include "src/kernel/activity/IoImpl.hpp"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
16 Io::Io(sg_storage_t storage, sg_size_t size, OpType type) : storage_(storage), size_(size), type_(type)
18 Activity::set_remaining(size_);
19 pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
24 simix::simcall([this] {
25 (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
27 .set_storage(storage_->get_impl())
32 state_ = State::STARTED;
38 simgrid::simix::simcall([this] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->cancel(); });
39 state_ = State::CANCELED;
45 simcall_io_wait(pimpl_);
46 state_ = State::FINISHED;
50 Io* Io::wait_for(double)
57 xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
59 if (state_ == State::FINISHED)
62 if (state_ == State::INITED)
70 /** @brief Returns the amount of flops that remain to be done */
71 double Io::get_remaining()
73 return simix::simcall(
74 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
77 sg_size_t Io::get_performed_ioops()
79 return simix::simcall(
80 [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
83 void intrusive_ptr_release(simgrid::s4u::Io* i)
85 if (i->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
86 std::atomic_thread_fence(std::memory_order_acquire);
91 void intrusive_ptr_add_ref(simgrid::s4u::Io* i)
93 i->refcount_.fetch_add(1, std::memory_order_relaxed);
96 } // namespace simgrid