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"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
18 pimpl_ = simcall_io_start(size_, storage_);
19 state_ = State::STARTED;
23 Activity* Io::cancel()
25 simgrid::simix::simcall([this] { dynamic_cast<kernel::activity::IoImpl*>(pimpl_.get())->cancel(); });
26 state_ = State::CANCELED;
30 // Activity* Exec::wait()
32 // simcall_execution_wait(pimpl_);
33 // state_ = State::FINISHED;
37 // Activity* Exec::wait(double timeout)
39 // THROW_UNIMPLEMENTED;
43 ///** @brief Returns whether the state of the exec is finished */
46 // xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
48 // if (state_ == State::FINISHED)
51 // if (state_ == State::INITED)
54 // if (simcall_execution_test(pimpl_)) {
55 // state_ = State::FINISHED;
62 /** @brief Returns the amount of flops that remain to be done */
63 double Io::get_remaining()
65 return simgrid::simix::simcall(
66 [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
69 // double Io::get_remaining_ratio()
71 // return simgrid::simix::simcall([this]() {
72 // return boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(pimpl_)->get_remaining_ratio();
76 void intrusive_ptr_release(simgrid::s4u::Io* e)
78 if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
79 std::atomic_thread_fence(std::memory_order_acquire);
84 void intrusive_ptr_add_ref(simgrid::s4u::Io* e)
86 e->refcount_.fetch_add(1, std::memory_order_relaxed);
89 } // namespace simgrid